pub struct ContextBuilder<P: Platform> { /* private fields */ }Expand description
Builder for assembling LLM context from multiple sources.
Combines configuration, memory, skills, and session history into a structured message list for the LLM pipeline. Each source is read asynchronously through the platform abstraction.
§Usage
let ctx = ContextBuilder::new(config, memory, skills, platform);
let system_prompt = ctx.build_system_prompt().await;
let messages = ctx.build_messages(&session, &["research"]).await;Implementations§
Source§impl<P: Platform> ContextBuilder<P>
impl<P: Platform> ContextBuilder<P>
Sourcepub fn new(
config: AgentsConfig,
memory: Arc<MemoryStore<P>>,
skills: Arc<SkillsLoader<P>>,
platform: Arc<P>,
) -> Self
pub fn new( config: AgentsConfig, memory: Arc<MemoryStore<P>>, skills: Arc<SkillsLoader<P>>, platform: Arc<P>, ) -> Self
Create a new context builder.
§Arguments
config– Agent configuration (system prompt, memory window, etc.)memory– Shared memory store for reading long-term memoryskills– Shared skills loader for reading active skill promptsplatform– Platform abstraction for filesystem/env access
Sourcepub async fn build_system_prompt(&self) -> String
pub async fn build_system_prompt(&self) -> String
Build the system prompt from configuration.
Assembles the core identity prompt. This includes:
- A static identity header describing the assistant
- Workspace path information
- Memory file paths for the agent to reference
The returned string is suitable for a role="system" message.
Sourcepub async fn build_messages(
&self,
session: &Session,
active_skills: &[String],
) -> Vec<LlmMessage>
pub async fn build_messages( &self, session: &Session, active_skills: &[String], ) -> Vec<LlmMessage>
Build the complete message list for an LLM call.
Assembles messages in the canonical order:
- System prompt (role=
"system") - Active skill prompts (role=
"system", one per skill) - Long-term memory context (role=
"system", if non-empty) - Conversation history from
session.get_history(memory_window)
The current user message is not included – the caller adds it after calling this method.
§Arguments
session– Current conversation sessionactive_skills– Names of skills to include in context
Sourcepub fn config(&self) -> &AgentsConfig
pub fn config(&self) -> &AgentsConfig
Get a reference to the agent configuration.
Sourcepub async fn build_system_prompt_for_agent(
&self,
agent: &AgentDefinition,
args: &str,
) -> String
pub async fn build_system_prompt_for_agent( &self, agent: &AgentDefinition, args: &str, ) -> String
Build a system prompt message for a specific agent definition.
Prepends the agent’s system_prompt (with template rendering)
to the standard system prompt. If the agent has no custom
system prompt, only the standard prompt is returned.
§Arguments
agent– The agent definition to injectargs– Arguments string for template variable expansion
Sourcepub async fn build_messages_for_agent(
&self,
session: &Session,
agent: &AgentDefinition,
args: &str,
extra_skill_instructions: Option<&str>,
) -> Vec<LlmMessage>
pub async fn build_messages_for_agent( &self, session: &Session, agent: &AgentDefinition, args: &str, extra_skill_instructions: Option<&str>, ) -> Vec<LlmMessage>
Build the complete message list for an agent-aware LLM call.
Like build_messages but additionally:
- Uses the agent’s system prompt (template-rendered)
- Activates the agent’s declared skills
- Appends any extra skill instructions as a system message
§Arguments
session– Current conversation sessionagent– Agent definition to useargs– Arguments string for template renderingextra_skill_instructions– Optional additional skill text to inject
Auto Trait Implementations§
impl<P> Freeze for ContextBuilder<P>
impl<P> !RefUnwindSafe for ContextBuilder<P>
impl<P> Send for ContextBuilder<P>
impl<P> Sync for ContextBuilder<P>
impl<P> Unpin for ContextBuilder<P>
impl<P> UnsafeUnpin for ContextBuilder<P>
impl<P> !UnwindSafe for ContextBuilder<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