pub struct Agent { /* private fields */ }Expand description
High-level agent facade.
Holds the LLM client and agent config. Workspace-independent.
Use Agent::session() to bind to a workspace.
Implementations§
Source§impl Agent
impl Agent
Sourcepub async fn new(config_source: impl Into<String>) -> Result<Self>
pub async fn new(config_source: impl Into<String>) -> Result<Self>
Create from a config file path or inline config string.
Auto-detects: file path (.hcl/.json) vs inline JSON vs inline HCL.
Sourcepub async fn create(config_source: impl Into<String>) -> Result<Self>
pub async fn create(config_source: impl Into<String>) -> Result<Self>
Create from a config file path or inline config string.
Alias for Agent::new() — provides a consistent API with
the Python and Node.js SDKs.
Sourcepub async fn from_config(config: CodeConfig) -> Result<Self>
pub async fn from_config(config: CodeConfig) -> Result<Self>
Create from a CodeConfig struct.
Sourcepub async fn refresh_mcp_tools(&self) -> Result<()>
pub async fn refresh_mcp_tools(&self) -> Result<()>
Re-fetch tool definitions from all connected global MCP servers and update the internal cache.
Call this when an MCP server has added or removed tools since the
agent was created. The refreshed tools will be visible to all
new sessions created after this call; existing sessions are
unaffected (their ToolExecutor snapshot is already built).
Sourcepub fn session(
&self,
workspace: impl Into<String>,
options: Option<SessionOptions>,
) -> Result<AgentSession>
pub fn session( &self, workspace: impl Into<String>, options: Option<SessionOptions>, ) -> Result<AgentSession>
Bind to a workspace directory, returning an AgentSession.
Pass None for defaults, or Some(SessionOptions) to override
the model, agent directories for this session.
Sourcepub fn session_for_agent(
&self,
workspace: impl Into<String>,
def: &AgentDefinition,
extra: Option<SessionOptions>,
) -> Result<AgentSession>
pub fn session_for_agent( &self, workspace: impl Into<String>, def: &AgentDefinition, extra: Option<SessionOptions>, ) -> Result<AgentSession>
Create a session pre-configured from an [AgentDefinition].
Maps the definition’s permissions, prompt, model, and max_steps
directly into SessionOptions, so markdown/YAML-defined subagents can
be used as crate::agent_teams::TeamRunner members without manual wiring.
The mapping follows the same logic as the built-in task tool:
permissions→permission_checkerprompt→prompt_slots.extramax_steps→max_tool_roundsmodel→model(as"provider/model"string)
extra can supply additional overrides (e.g. planning_enabled) that
take precedence over the definition’s values.
Sourcepub fn resume_session(
&self,
session_id: &str,
options: SessionOptions,
) -> Result<AgentSession>
pub fn resume_session( &self, session_id: &str, options: SessionOptions, ) -> Result<AgentSession>
Resume a previously saved session by ID.
Loads the session data from the store, rebuilds the AgentSession with
the saved conversation history, and returns it ready for continued use.
The options must include a session_store (or with_file_session_store)
that contains the saved session.