pub struct AgentContext<T> {
pub llm: LlmClient,
/* private fields */
}Expand description
Context provided to agent handlers.
This gives agents access to LLM inference and the ability to emit results.
Fields§
§llm: LlmClientLLM client for inference calls.
Implementations§
Source§impl<T> AgentContext<T>
impl<T> AgentContext<T>
Sourcepub fn emit(&mut self, value: T) -> SageResult<T>where
T: Clone,
pub fn emit(&mut self, value: T) -> SageResult<T>where
T: Clone,
Emit a value to the awaiter.
This should be called once at the end of the agent’s execution. Calling emit multiple times is a no-op after the first call.
Sourcepub async fn infer<R>(&self, prompt: &str) -> SageResult<R>where
R: DeserializeOwned,
pub async fn infer<R>(&self, prompt: &str) -> SageResult<R>where
R: DeserializeOwned,
Call the LLM with a prompt and parse the response.
Sourcepub async fn infer_string(&self, prompt: &str) -> SageResult<String>
pub async fn infer_string(&self, prompt: &str) -> SageResult<String>
Call the LLM with a prompt and return the raw string response.
Sourcepub async fn receive<M>(&mut self) -> SageResult<M>where
M: DeserializeOwned,
pub async fn receive<M>(&mut self) -> SageResult<M>where
M: DeserializeOwned,
Receive a message from the agent’s mailbox.
This blocks until a message is available. The message is deserialized into the specified type.
Sourcepub async fn receive_timeout<M>(
&mut self,
timeout: Duration,
) -> SageResult<Option<M>>where
M: DeserializeOwned,
pub async fn receive_timeout<M>(
&mut self,
timeout: Duration,
) -> SageResult<Option<M>>where
M: DeserializeOwned,
Receive a message with a timeout.
Returns None if the timeout expires before a message arrives.
Auto Trait Implementations§
impl<T> Freeze for AgentContext<T>
impl<T> !RefUnwindSafe for AgentContext<T>
impl<T> Send for AgentContext<T>where
T: Send,
impl<T> Sync for AgentContext<T>where
T: Send,
impl<T> Unpin for AgentContext<T>
impl<T> UnsafeUnpin for AgentContext<T>
impl<T> !UnwindSafe for AgentContext<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more