pub struct AppContext<P: Platform> { /* private fields */ }Expand description
Fully initialized application context.
Holds all dependencies needed to run the agent loop. Created via
AppContext::new and consumed via AppContext::into_agent_loop.
The generic parameter P is the platform implementation (e.g.
NativePlatform for native,
a WASM platform for browser environments).
Implementations§
Source§impl<P: Platform> AppContext<P>
impl<P: Platform> AppContext<P>
Sourcepub async fn new(config: Config, platform: Arc<P>) -> Result<Self>
pub async fn new(config: Config, platform: Arc<P>) -> Result<Self>
Initialize all components from configuration and platform.
This is the primary constructor. It:
- Creates the
MessageBus - Initializes the
SessionManager(discovers/creates sessions dir) - Initializes the
MemoryStore(discovers memory dir) - Initializes the
SkillsLoader(discovers skills dir) - Creates the
ContextBuilder - Creates an empty
ToolRegistry(caller registers tools after) - Wires the default Level 0 pipeline (keyword classifier, static router, token budget assembler, stub transport, noop scorer, noop learner)
§Errors
Returns [ClawftError] if the home directory cannot be determined
or the sessions directory cannot be created.
Sourcepub fn into_agent_loop(self) -> AgentLoop<P>
pub fn into_agent_loop(self) -> AgentLoop<P>
Consume the context and produce a running AgentLoop.
All dependencies are moved into the agent loop. After this call,
the AppContext is consumed and cannot be reused.
Sourcepub fn bus(&self) -> &Arc<MessageBus>
pub fn bus(&self) -> &Arc<MessageBus>
Get a reference to the message bus.
Channel adapters should clone the inbound sender from here
before the context is consumed by [into_agent_loop].
Sourcepub fn tools_mut(&mut self) -> &mut ToolRegistry
pub fn tools_mut(&mut self) -> &mut ToolRegistry
Get a mutable reference to the tool registry.
Call this to register tools before converting to an agent loop.
§Panics
Panics if Arc clones have already been taken (e.g. via tools_arc()).
Always call tools_mut() for registration before sharing the registry.
Sourcepub fn tools(&self) -> &Arc<ToolRegistry>
pub fn tools(&self) -> &Arc<ToolRegistry>
Get a reference to the tool registry.
Sourcepub fn tools_arc(&self) -> Arc<ToolRegistry>
pub fn tools_arc(&self) -> Arc<ToolRegistry>
Get a clone of the Arc<ToolRegistry> for sharing with other components.
Sourcepub fn sessions(&self) -> &Arc<SessionManager<P>>
pub fn sessions(&self) -> &Arc<SessionManager<P>>
Get a reference to the session manager.
Sourcepub fn memory(&self) -> &Arc<MemoryStore<P>>
pub fn memory(&self) -> &Arc<MemoryStore<P>>
Get a reference to the shared memory store.
Sourcepub fn skills(&self) -> &Arc<SkillsLoader<P>>
pub fn skills(&self) -> &Arc<SkillsLoader<P>>
Get a reference to the shared skills loader.
Sourcepub fn set_auto_delegation(&mut self, delegation: Arc<dyn AutoDelegation>)
pub fn set_auto_delegation(&mut self, delegation: Arc<dyn AutoDelegation>)
Set an auto-delegation router for pre-LLM routing.
When set, inbound messages are checked against delegation rules
before the local LLM is invoked. Matching messages are routed
directly to delegate_task.
Sourcepub fn set_pipeline(&mut self, pipeline: PipelineRegistry)
pub fn set_pipeline(&mut self, pipeline: PipelineRegistry)
Replace the pipeline registry with a custom one.
Use this to inject a transport backed by a real LLM provider or to register specialized pipelines for specific task types.
Sourcepub fn enable_live_llm(&mut self)
pub fn enable_live_llm(&mut self)
Replace the pipeline with a live LLM-backed pipeline.
Convenience method that calls build_live_pipeline and sets it
as the active pipeline, enabling real LLM calls through the
clawft-llm provider resolved from configuration.
Only available with the native feature.
Auto Trait Implementations§
impl<P> Freeze for AppContext<P>
impl<P> !RefUnwindSafe for AppContext<P>
impl<P> Send for AppContext<P>
impl<P> Sync for AppContext<P>
impl<P> Unpin for AppContext<P>
impl<P> UnsafeUnpin for AppContext<P>
impl<P> !UnwindSafe for AppContext<P>
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
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>
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>
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 more