pub trait ExternalPolicy: DecisionPolicy {
// Required method
fn submitted_response(
&self,
ticket: &DecisionTicket,
) -> Option<ExternalDecisionResponse>;
// Provided method
fn external_request(
&self,
ticket: &DecisionTicket,
) -> ExternalDecisionRequest { ... }
}Required Methods§
fn submitted_response( &self, ticket: &DecisionTicket, ) -> Option<ExternalDecisionResponse>
Provided Methods§
Sourcefn external_request(&self, ticket: &DecisionTicket) -> ExternalDecisionRequest
fn external_request(&self, ticket: &DecisionTicket) -> ExternalDecisionRequest
Examples found in repository?
examples/uncertainty_resolution.rs (line 199)
174fn llm_interface_branch() -> Result<(), Box<dyn std::error::Error>> {
175 let mut canwu = Canwu::demo(202)?;
176 let ticket_id = DecisionTicketId::new(2);
177 enqueue_ticket(
178 &mut canwu,
179 ticket_id,
180 10,
181 DecisionControllerBinding::new(
182 "law-llm-controller",
183 DecisionPolicyIdentity::new(DecisionPolicyKind::Llm, "strict-law-selector", "1"),
184 DecisionAuthority::Actor {
185 actor: Canwu::demo_ids().commander,
186 },
187 ),
188 )?;
189 let mut policy = QueuedLlmPolicy::new(
190 "strict-law-selector",
191 "1",
192 LlmModelIdentity {
193 provider: "not-connected".to_owned(),
194 model: "host-selected-model".to_owned(),
195 prompt_contract: "return one existing option_id and no new action".to_owned(),
196 },
197 );
198 let ticket = canwu.decision_ticket(ticket_id).expect("LLM ticket");
199 let request = policy.external_request(ticket);
200 println!("llm_request={}", serde_json::to_string(&request)?);
201
202 // A real host sends `request` to its model and parses a strict structured
203 // answer. This example supplies the same response object without making a
204 // network call.
205 policy.submit(
206 ticket_id,
207 ExternalDecisionResponse {
208 ticket_version: request.ticket_version,
209 option_id: "pass".to_owned(),
210 provider: "not-connected".to_owned(),
211 request_id: "example-response-1".to_owned(),
212 metadata: BTreeMap::new(),
213 },
214 )?;
215 let evaluation = canwu.drive_decision(
216 canwu.time(),
217 0,
218 DecisionRequestId::new(12),
219 None,
220 ticket_id,
221 &policy,
222 )?;
223 assert!(matches!(evaluation, DecisionEvaluation::Prepared(_)));
224 canwu.step_canonical()?.expect("LLM decision boundary");
225 Ok(())
226}Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".