Expand description
Simple recursive agent using event-driven architecture.
This module provides a declarative, event-driven agent that recursively attempts to solve problems using available tools. The agent continues iterating until it succeeds, fails explicitly, or reaches the maximum number of iterations.
§Architecture
The agent uses three main components:
- GoalState - Tracks the problem-solving state through iterations
- EventEmitter - Manages event subscriptions and async dispatch
- SimpleRecursiveAgent - Orchestrates the problem-solving process
§Events
The agent emits the following events during problem-solving:
GoalSubmittedEvent- When a problem is submittedIterationCompletedEvent- After each iteration completesGoalAchievedEvent- When the goal is successfully achievedGoalFailedEvent- When the goal explicitly failsTimeoutEvent- When the process times out
§Examples
ⓘ
use mojentic::agents::SimpleRecursiveAgent;
use mojentic::llm::{LlmBroker, LlmGateway};
use mojentic::llm::gateways::OllamaGateway;
use mojentic::llm::tools::simple_date_tool::SimpleDateTool;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let gateway = Arc::new(OllamaGateway::default());
let broker = Arc::new(LlmBroker::new("qwen3:32b", gateway, None));
let tools: Vec<Box<dyn LlmTool>> = vec![Box::new(SimpleDateTool)];
let agent = SimpleRecursiveAgent::builder(broker)
.tools(tools)
.max_iterations(5)
.build();
// Subscribe to events
agent.emitter.subscribe(|event: IterationCompletedEvent| {
println!("Iteration {}: {}", event.state.iteration, event.response);
});
let result = agent.solve("What's the date next Friday?").await?;
println!("Result: {}", result);
Ok(())
}§Completion Indicators
The agent monitors responses for these keywords (case-insensitive, word boundaries):
- “DONE” - Task completed successfully
- “FAIL” - Task cannot be completed
Structs§
- Event
Emitter - A simple event emitter that allows subscribing to and emitting events.
- Goal
Achieved Event - Event triggered when a goal is successfully achieved.
- Goal
Failed Event - Event triggered when a goal cannot be solved.
- Goal
State - Represents the state of a problem-solving process.
- Goal
Submitted Event - Event triggered when a goal is submitted for solving.
- Iteration
Completed Event - Event triggered when an iteration of the problem-solving process is completed.
- Simple
Recursive Agent - An agent that recursively attempts to solve a problem using available tools.
- Simple
Recursive Agent Builder - Builder for constructing a
SimpleRecursiveAgentwith custom configuration. - Timeout
Event - Event triggered when the problem-solving process times out.
Enums§
- AnySolver
Event - Union type of all solver events
Traits§
- Solver
Event - Base trait for solver events.