pub struct Context { /* private fields */ }Expand description
Execution context shared across an agent run.
Holds the configured LLM provider, accumulated chat messages, optional
memory and tools, agent configuration, ephemeral execution state, and
an optional event transmitter used by actor-based agents to emit protocol
Events. Also carries a stream flag to indicate streaming mode.
Implementations§
Source§impl Context
impl Context
pub fn new(llm: Arc<dyn LLMProvider>, tx: Option<Sender<Event>>) -> Self
pub async fn publish<M: ActorMessage>( &self, topic: Topic<M>, message: M, ) -> Result<(), ContextError>
pub fn with_memory( self, memory: Option<Arc<Mutex<Box<dyn MemoryProvider>>>>, ) -> Self
pub fn with_tools(self, tools: Vec<Box<dyn ToolT>>) -> Self
pub fn with_serialized_tools(self, tools: Option<Arc<Vec<Tool>>>) -> Self
pub fn with_config(self, config: AgentConfig) -> Self
pub fn with_messages(self, messages: Vec<ChatMessage>) -> Self
pub fn with_stream(self, stream: bool) -> Self
pub fn llm(&self) -> &Arc<dyn LLMProvider>
pub fn messages(&self) -> &[ChatMessage]
pub fn memory(&self) -> Option<Arc<Mutex<Box<dyn MemoryProvider>>>>
pub fn tools(&self) -> &[Box<dyn ToolT>]
pub fn serialized_tools(&self) -> Option<Arc<Vec<Tool>>>
pub fn config(&self) -> &AgentConfig
pub fn state(&self) -> Arc<Mutex<AgentState>>
Sourcepub fn tx(&self) -> Result<Sender<Event>, ContextError>
pub fn tx(&self) -> Result<Sender<Event>, ContextError>
Get a clone of the event transmitter (only present for Actor agents).
pub fn stream(&self) -> bool
Auto Trait Implementations§
impl Freeze for Context
impl !RefUnwindSafe for Context
impl Send for Context
impl Sync for Context
impl Unpin for Context
impl UnsafeUnpin for Context
impl !UnwindSafe for Context
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Message for T
impl<T> Message for T
Source§fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
fn from_boxed(m: BoxedMessage) -> Result<Self, BoxedDowncastErr>
Convert a BoxedMessage to this concrete type
Source§fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
fn box_message(self, pid: &ActorId) -> Result<BoxedMessage, BoxedDowncastErr>
Convert this message to a BoxedMessage