pub struct AgentContext<B: ContextBackend> { /* private fields */ }Expand description
LLM 对话上下文管理器,kameo Actor。
管理三区 + 可选 Scratch 消息模型(immutable → compressed → incremental → scratch),提供:
- 消息增删改查(
RequestAppend、RequestUpdate、RequestRemove等) - 对话发送(
RequestSend、RequestSendStream),支持通过super::CommonOpts::scratch追加临时元数据 - 上下文压缩(
RequestCompress) - Token 估算(
RequestEstimateTokens) - 压缩订阅管理(
RequestSubscribeCompressed、RequestUnsubscribeCompressed)
§构造
ⓘ
let actor_ref = AgentContext::spawn(AgentContext::new(backend, vec![]));Implementations§
Source§impl<B: ContextBackend> AgentContext<B>
impl<B: ContextBackend> AgentContext<B>
Sourcepub fn new(backend: B, immutable: Vec<B::Message>) -> Self
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>
impl<B: ContextBackend> Actor for AgentContext<B>
Source§type Args = AgentContext<B>
type Args = AgentContext<B>
Arguments to initialize the actor. Read more
Source§type Error = Infallible
type Error = Infallible
Actor error type. Read more
Source§fn name() -> &'static str
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>
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
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
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
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
Source§fn on_link_died(
&mut self,
actor_ref: WeakActorRef<Self>,
id: ActorId,
reason: ActorStopReason,
) -> impl Future<Output = Result<ControlFlow<ActorStopReason>, Self::Error>> + Send
fn on_link_died( &mut self, actor_ref: WeakActorRef<Self>, id: ActorId, reason: ActorStopReason, ) -> impl Future<Output = Result<ControlFlow<ActorStopReason>, Self::Error>> + Send
Called when a linked actor dies. Read more
Source§impl<B: ContextBackend> Message<RequestAppend<<B as ContextBackend>::Message>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestAppend<<B as ContextBackend>::Message>> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestClear> for AgentContext<B>
impl<B: ContextBackend> Message<RequestClear> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestCompress<<B as ContextBackend>::Opts>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestCompress<<B as ContextBackend>::Opts>> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestCompressed> for AgentContext<B>
impl<B: ContextBackend> Message<RequestCompressed> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestEstimateTokens> for AgentContext<B>
impl<B: ContextBackend> Message<RequestEstimateTokens> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestExportAll> for AgentContext<B>
impl<B: ContextBackend> Message<RequestExportAll> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestExportIncremental> for AgentContext<B>
impl<B: ContextBackend> Message<RequestExportIncremental> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestExtend<<B as ContextBackend>::Message>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestExtend<<B as ContextBackend>::Message>> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestFindByRole> for AgentContext<B>
impl<B: ContextBackend> Message<RequestFindByRole> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestGet> for AgentContext<B>
impl<B: ContextBackend> Message<RequestGet> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestImmutable> for AgentContext<B>
impl<B: ContextBackend> Message<RequestImmutable> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestImportIncremental> for AgentContext<B>
impl<B: ContextBackend> Message<RequestImportIncremental> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestIncremental> for AgentContext<B>
impl<B: ContextBackend> Message<RequestIncremental> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestInsert<<B as ContextBackend>::Message>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestInsert<<B as ContextBackend>::Message>> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestIsEmpty> for AgentContext<B>
impl<B: ContextBackend> Message<RequestIsEmpty> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestLen> for AgentContext<B>
impl<B: ContextBackend> Message<RequestLen> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestMessages> for AgentContext<B>
impl<B: ContextBackend> Message<RequestMessages> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestPop> for AgentContext<B>
impl<B: ContextBackend> Message<RequestPop> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestRemove> for AgentContext<B>
impl<B: ContextBackend> Message<RequestRemove> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestRetain> for AgentContext<B>
impl<B: ContextBackend> Message<RequestRetain> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestSend<<B as ContextBackend>::Opts>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestSend<<B as ContextBackend>::Opts>> for AgentContext<B>
Source§type Reply = Result<<B as ContextBackend>::Response, AgentError>
type Reply = Result<<B as ContextBackend>::Response, AgentError>
The reply sent back to the message caller.
Source§impl<B: ContextBackend + Clone> Message<RequestSendStream<<B as ContextBackend>::Opts>> for AgentContext<B>
impl<B: ContextBackend + Clone> Message<RequestSendStream<<B as ContextBackend>::Opts>> for AgentContext<B>
Source§type Reply = Result<AgentSendStream<B>, AgentError>
type Reply = Result<AgentSendStream<B>, AgentError>
The reply sent back to the message caller.
Source§impl<B: ContextBackend> Message<RequestSubscribeCompressed<<B as ContextBackend>::Message>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestSubscribeCompressed<<B as ContextBackend>::Message>> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestUnsubscribeCompressed> for AgentContext<B>
impl<B: ContextBackend> Message<RequestUnsubscribeCompressed> for AgentContext<B>
Source§impl<B: ContextBackend> Message<RequestUpdate<<B as ContextBackend>::Message>> for AgentContext<B>
impl<B: ContextBackend> Message<RequestUpdate<<B as ContextBackend>::Message>> for AgentContext<B>
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>
impl<B> UnsafeUnpin for AgentContext<B>where
B: UnsafeUnpin,
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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
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>
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)
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)
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
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<A, T> DynMessage<A> for T
impl<A, T> DynMessage<A> for T
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>>
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§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<A> Spawn for Awhere
A: Actor,
impl<A> Spawn for Awhere
A: Actor,
Source§fn spawn(args: Self::Args) -> ActorRef<Self>
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>
fn spawn_default() -> ActorRef<Self>
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>
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
Source§fn spawn_link<L>(
link_ref: &ActorRef<L>,
args: Self::Args,
) -> impl Future<Output = ActorRef<Self>> + Sendwhere
L: Actor,
fn spawn_link<L>(
link_ref: &ActorRef<L>,
args: Self::Args,
) -> impl Future<Output = ActorRef<Self>> + Sendwhere
L: Actor,
Spawns and links the actor in a Tokio task with a default bounded mailbox. Read more
Source§fn spawn_link_with_mailbox<L>(
link_ref: &ActorRef<L>,
args: Self::Args,
_: (MailboxSender<Self>, MailboxReceiver<Self>),
) -> impl Future<Output = ActorRef<Self>> + Sendwhere
L: Actor,
fn spawn_link_with_mailbox<L>(
link_ref: &ActorRef<L>,
args: Self::Args,
_: (MailboxSender<Self>, MailboxReceiver<Self>),
) -> impl Future<Output = ActorRef<Self>> + Sendwhere
L: Actor,
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>
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>
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