Skip to main content

AgentContext

Struct AgentContext 

Source
pub struct AgentContext<B: ContextBackend> { /* private fields */ }
Expand description

LLM 对话上下文管理器,kameo Actor。

管理三区 + 可选 Scratch 消息模型(immutable → compressed → incremental → scratch),提供:

§构造

let actor_ref = AgentContext::spawn(AgentContext::new(backend, vec![]));

Implementations§

Source§

impl<B: ContextBackend> AgentContext<B>

Source

pub fn new(backend: B, immutable: Vec<B::Message>) -> Self

创建新的上下文管理器。

  • backend: 实现了 ContextBackend 的 LLM 后端实例
  • immutable: 初始不可变消息(系统提示词等),放入 immutable 区

Trait Implementations§

Source§

impl<B: ContextBackend> Actor for AgentContext<B>

Source§

type Args = AgentContext<B>

Arguments to initialize the actor. Read more
Source§

type Error = Infallible

Actor error type. Read more
Source§

fn name() -> &'static str

The name of the actor, which can be useful for logging or debugging. Read more
Source§

async fn on_start( state: Self::Args, _actor_ref: ActorRef<Self>, ) -> Result<Self, Self::Error>

Called when the actor starts, before it processes any messages. Read more
Source§

fn supervision_strategy() -> SupervisionStrategy

Defines the supervision strategy for this actor when acting as a supervisor. Read more
Source§

fn on_message( &mut self, msg: Box<dyn DynMessage<Self>>, actor_ref: ActorRef<Self>, tx: Option<Sender<Result<Box<dyn Any + Send>, SendError<Box<dyn Any + Send>, Box<dyn Any + Send>>>>>, stop: &mut bool, ) -> impl Future<Output = Result<(), Box<dyn ReplyError>>> + Send

Called when the actor receives a message to be processed. Read more
Source§

fn on_panic( &mut self, actor_ref: WeakActorRef<Self>, err: PanicError, ) -> impl Future<Output = Result<ControlFlow<ActorStopReason>, Self::Error>> + Send

Called when the actor encounters a panic or an error during “tell” message handling. Read more
Called when a linked actor dies. Read more
Source§

fn on_stop( &mut self, actor_ref: WeakActorRef<Self>, reason: ActorStopReason, ) -> impl Future<Output = Result<(), Self::Error>> + Send

Called before the actor stops. Read more
Source§

fn next( &mut self, actor_ref: WeakActorRef<Self>, mailbox_rx: &mut MailboxReceiver<Self>, ) -> impl Future<Output = Result<Option<Signal<Self>>, Self::Error>> + Send

Awaits the next signal typically from the mailbox. Read more
Source§

impl<B: ContextBackend> Message<RequestAppend<<B as ContextBackend>::Message>> for AgentContext<B>

Source§

type Reply = ()

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestAppend<B::Message>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestClear> for AgentContext<B>

Source§

type Reply = ()

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestClear, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestCompress<<B as ContextBackend>::Opts>> for AgentContext<B>

Source§

type Reply = Result<(), AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestCompress<B::Opts>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestCompressed> for AgentContext<B>

Source§

type Reply = Vec<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestCompressed, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestEstimateTokens> for AgentContext<B>

Source§

type Reply = usize

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestEstimateTokens, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestExportAll> for AgentContext<B>

Source§

type Reply = Result<String, AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestExportAll, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestExportIncremental> for AgentContext<B>

Source§

type Reply = Result<String, AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestExportIncremental, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestExtend<<B as ContextBackend>::Message>> for AgentContext<B>

Source§

type Reply = ()

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestExtend<B::Message>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestFindByRole> for AgentContext<B>

Source§

type Reply = Vec<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestFindByRole, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestGet> for AgentContext<B>

Source§

type Reply = Option<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestGet, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestImmutable> for AgentContext<B>

Source§

type Reply = Vec<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestImmutable, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestImportIncremental> for AgentContext<B>

Source§

type Reply = Result<(), AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestImportIncremental, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestIncremental> for AgentContext<B>

Source§

type Reply = Vec<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestIncremental, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestInsert<<B as ContextBackend>::Message>> for AgentContext<B>

Source§

type Reply = Result<(), AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestInsert<B::Message>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestIsEmpty> for AgentContext<B>

Source§

type Reply = bool

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestIsEmpty, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestLen> for AgentContext<B>

Source§

type Reply = usize

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestLen, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestMessages> for AgentContext<B>

Source§

type Reply = Vec<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestMessages, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestPop> for AgentContext<B>

Source§

type Reply = Option<<B as ContextBackend>::Message>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestPop, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestRemove> for AgentContext<B>

Source§

type Reply = Result<(), AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestRemove, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestRetain> for AgentContext<B>

Source§

type Reply = ()

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestRetain, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestSend<<B as ContextBackend>::Opts>> for AgentContext<B>

Source§

type Reply = Result<<B as ContextBackend>::Response, AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestSend<B::Opts>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend + Clone> Message<RequestSendStream<<B as ContextBackend>::Opts>> for AgentContext<B>

Source§

type Reply = Result<AgentSendStream<B>, AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestSendStream<B::Opts>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestSubscribeCompressed<<B as ContextBackend>::Message>> for AgentContext<B>

Source§

type Reply = ()

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestSubscribeCompressed<B::Message>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestUnsubscribeCompressed> for AgentContext<B>

Source§

type Reply = ()

The reply sent back to the message caller.
Source§

async fn handle( &mut self, _msg: RequestUnsubscribeCompressed, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more
Source§

impl<B: ContextBackend> Message<RequestUpdate<<B as ContextBackend>::Message>> for AgentContext<B>

Source§

type Reply = Result<(), AgentError>

The reply sent back to the message caller.
Source§

async fn handle( &mut self, msg: RequestUpdate<B::Message>, _ctx: &mut Context<Self, Self::Reply>, ) -> Self::Reply

Handler for this message.
Source§

fn name() -> &'static str

The name of the message, which can be useful for logging or debugging. Read more

Auto Trait Implementations§

§

impl<B> !RefUnwindSafe for AgentContext<B>

§

impl<B> !UnwindSafe for AgentContext<B>

§

impl<B> Freeze for AgentContext<B>
where B: Freeze,

§

impl<B> Send for AgentContext<B>

§

impl<B> Sync for AgentContext<B>

§

impl<B> Unpin for AgentContext<B>
where B: Unpin, <B as ContextBackend>::Message: Unpin,

§

impl<B> UnsafeUnpin for AgentContext<B>
where B: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> DowncastSend for T
where T: Any + Send,

Source§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_sync(self: Box<T>) -> Box<dyn Any + Sync + Send>

Converts Box<Trait> (where Trait: DowncastSync) to Box<dyn Any + Send + Sync>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Converts Arc<Trait> (where Trait: DowncastSync) to Arc<Any>, which can then be downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<A, T> DynMessage<A> for T
where A: Actor + Message<T>, T: Send + 'static,

Source§

fn handle_dyn<'a>( self: Box<T>, state: &'a mut A, actor_ref: ActorRef<A>, tx: Option<Sender<Result<Box<dyn Any + Send>, SendError<Box<dyn Any + Send>, Box<dyn Any + Send>>>>>, stop: &'a mut bool, ) -> Pin<Box<dyn Future<Output = Result<(), Box<dyn ReplyError>>> + Send + 'a>>

Handles the dyn message with the provided actor state, ref, and reply sender.
Source§

fn as_any(self: Box<T>) -> Box<dyn Any>

Casts the type to a Box<dyn Any>.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<A> Spawn for A
where A: Actor,

Source§

fn spawn(args: Self::Args) -> ActorRef<Self>

Spawns the actor in a Tokio task, running asynchronously with a default bounded mailbox. Read more
Source§

fn spawn_default() -> ActorRef<Self>
where Self::Args: Default,

Spawns the actor with default initialization in a Tokio task. Read more
Source§

fn spawn_with_mailbox( args: Self::Args, _: (MailboxSender<Self>, MailboxReceiver<Self>), ) -> ActorRef<Self>

Spawns the actor in a Tokio task with a specific mailbox configuration. Read more
Spawns and links the actor in a Tokio task with a default bounded mailbox. Read more
Spawns and links the actor in a Tokio task with a specific mailbox configuration. Read more
Source§

fn spawn_in_thread(args: Self::Args) -> ActorRef<Self>

Spawns the actor in its own dedicated thread with a default bounded mailbox. Read more
Source§

fn spawn_in_thread_with_mailbox( args: Self::Args, _: (MailboxSender<Self>, MailboxReceiver<Self>), ) -> ActorRef<Self>

Spawns the actor in its own dedicated thread with a specific mailbox configuration. Read more
Source§

fn prepare() -> PreparedActor<Self>

Creates a new prepared actor, allowing access to its ActorRef before spawning. Read more
Source§

fn prepare_with_mailbox( _: (MailboxSender<Self>, MailboxReceiver<Self>), ) -> PreparedActor<Self>

Creates a new prepared actor with a specific mailbox configuration, allowing access to its ActorRef before spawning. Read more
Source§

fn supervise<A>( supervisor_ref: &ActorRef<A>, args: Self::Args, ) -> SupervisedActorBuilder<'_, A, Self>
where A: Actor, Self::Args: Clone + Sync,

Creates a supervised child actor under a supervisor. Read more
Source§

fn supervise_with<A>( supervisor_ref: &ActorRef<A>, f: impl Fn() -> Self::Args + Send + Sync + 'static, ) -> SupervisedActorBuilder<'_, A, Self>
where A: Actor,

Creates a supervised child actor with a factory function for generating args. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more