pub struct Agent { /* private fields */ }Expand description
A ReAct agent that owns its configuration, tools and history (no
lifetimes to manage). Same behaviour as LoopRunner.
use wasm_agent::{Agent, AgentConfig, ReActStep, ToolSpec};
use wasm_agent::types::ToolResult;
let mut agent = Agent::new(AgentConfig::default());
agent.tools_mut().register(
ToolSpec::new("echo", "Repeats its input", r#"{"type":"string"}"#),
Box::new(|s: &str| ToolResult { tool_name: "echo".into(), output: s.into(), success: true }),
)?;
agent.step("Action: echo(hi)")?;
assert_eq!(agent.step("Final Answer: done")?, ReActStep::FinalAnswer("done".into()));Implementations§
Source§impl Agent
impl Agent
Sourcepub fn new(config: AgentConfig) -> Self
pub fn new(config: AgentConfig) -> Self
An agent with no tools yet.
Sourcepub fn with_tools(config: AgentConfig, registry: ToolRegistry) -> Self
pub fn with_tools(config: AgentConfig, registry: ToolRegistry) -> Self
An agent with the given tools.
Sourcepub fn tools_mut(&mut self) -> &mut ToolRegistry
pub fn tools_mut(&mut self) -> &mut ToolRegistry
The tool registry, to register more tools.
Sourcepub fn tools(&self) -> &ToolRegistry
pub fn tools(&self) -> &ToolRegistry
The tool registry.
Sourcepub fn config(&self) -> &AgentConfig
pub fn config(&self) -> &AgentConfig
The configuration.
Sourcepub fn add_system_prompt(&mut self)
pub fn add_system_prompt(&mut self)
Adds the standard ReAct system prompt as the first message.
Sourcepub fn step_at(
&mut self,
llm_response: &str,
now_ms: f64,
) -> Result<ReActStep, AgentError>
pub fn step_at( &mut self, llm_response: &str, now_ms: f64, ) -> Result<ReActStep, AgentError>
Sourcepub fn step_response(
&mut self,
response_json: &str,
) -> Result<NativeStep, AgentError>
pub fn step_response( &mut self, response_json: &str, ) -> Result<NativeStep, AgentError>
Sourcepub fn transcript(&self) -> String
pub fn transcript(&self) -> String
Sourcepub fn history(&self) -> &ConversationHistory
pub fn history(&self) -> &ConversationHistory
The conversation history.
Sourcepub fn iteration_count(&self) -> usize
pub fn iteration_count(&self) -> usize
Number of model responses processed so far.
Auto Trait Implementations§
impl !RefUnwindSafe for Agent
impl !Send for Agent
impl !Sync for Agent
impl !UnwindSafe for Agent
impl Freeze for Agent
impl Unpin for Agent
impl UnsafeUnpin for Agent
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