Skip to main content

Module agent

Module agent 

Source
Expand description

§Module: Agent

§Responsibility

Provides a ReAct (Thought-Action-Observation) agent loop with pluggable tools. Mirrors the public API of wasm-agent.

§Guarantees

  • Deterministic: the loop terminates after at most max_iterations cycles
  • Non-panicking: all operations return Result
  • Tool handlers support both sync and async Fn closures

§NOT Responsible For

  • Actual LLM inference (callers supply a mock/stub inference fn)
  • WASM compilation or browser execution
  • Streaming partial responses

Structs§

AgentConfig
Configuration for the ReAct agent loop.
InMemoryToolCache
A simple in-memory ToolCache backed by a Mutex<HashMap>.
Message
A single message in the conversation history.
ReActLoop
The ReAct agent loop.
ReActStep
A single ReAct step: Thought → Action → Observation.
ToolRegistry
Registry of available tools for the agent loop.
ToolSpec
Describes and implements a single callable tool.

Enums§

Action
A parsed action from a ReAct step.
AgentError
Agent-specific errors, mirrors wasm-agent::AgentError.
Role
Role of a message in a conversation.

Traits§

Observer
Hook trait for observing agent loop events.
ToolCache
Cache for tool call results.
ToolValidator
Declarative argument validator for a ToolSpec.

Functions§

make_action_hook
Create an ActionHook from a plain async fn or closure.
parse_react_step
Parses a ReAct response string into a ReActStep.

Type Aliases§

ActionHook
Async hook called before each tool action. Return true to proceed, false to block.
AsyncToolFuture
A pinned, boxed future returning a Value. Used for async tool handlers.
AsyncToolHandler
An async tool handler closure.
AsyncToolResultFuture
A pinned, boxed future returning Result<Value, String>. Used for fallible async tool handlers.