Autonomous Agent
Autonomous Agent
The Autonomous Agent pattern is a design where an agent operates independently to achieve goals using available tools and resources.
Basic Structure
states:
- id: start
type: initial
next: plan_action
- id: plan_action
type: llm
model: planner
prompt: |
Plan the next action to achieve this goal:
{goal}
Available tools:
{tools}
Current state:
{state}
input:
goal: "${input.goal}"
tools: "${context.available_tools}"
state: "${context.current_state}"
next: execute_action
- id: execute_action
type: tool
tool: "${previous.output.tool}"
parameters: "${previous.output.parameters}"
next: evaluate_result
- id: evaluate_result
type: llm
model: evaluator
prompt: |
Evaluate the result of this action:
Action: {action}
Result: {result}
Goal: {goal}
Should we:
1. Continue with next action
2. Retry current action
3. End execution
input:
action: "${states.execute_action.input}"
result: "${previous.output}"
goal: "${input.goal}"
transitions:
- when: "${output.decision === 'continue'}"
next: plan_action
- when: "${output.decision === 'retry'}"
next: execute_action
- next: end
- id: end
type: output
value: "${context.final_result}"Common Use Cases
1. Task Automation
states:
- id: start
type: initial
next: plan_task
- id: plan_task
type: llm
model: planner
prompt: |
Plan steps to complete this task:
{task}
Available tools:
- file_operations
- data_processing
- api_calls
input:
task: "${input.task}"
next: execute_step
- id: execute_step
type: tool
tool: "${previous.output.tool}"
parameters: "${previous.output.parameters}"
next: evaluate_step
- id: evaluate_step
type: llm
model: evaluator
prompt: |
Evaluate step completion:
Step: {step}
Result: {result}
Task: {task}
input:
step: "${states.execute_step.input}"
result: "${previous.output}"
task: "${input.task}"
transitions:
- when: "${output.status === 'success'}"
next: plan_task
- when: "${output.status === 'retry'}"
next: execute_step
- next: end2. Research Assistant
states:
- id: start
type: initial
next: plan_research
- id: plan_research
type: llm
model: planner
prompt: |
Plan research steps for:
{topic}
Available tools:
- web_search
- document_analysis
- data_extraction
input:
topic: "${input.topic}"
next: execute_research
- id: execute_research
type: tool
tool: "${previous.output.tool}"
parameters: "${previous.output.parameters}"
next: evaluate_research
- id: evaluate_research
type: llm
model: evaluator
prompt: |
Evaluate research progress:
Step: {step}
Findings: {findings}
Topic: {topic}
input:
step: "${states.execute_research.input}"
findings: "${previous.output}"
topic: "${input.topic}"
transitions:
- when: "${output.status === 'continue'}"
next: plan_research
- when: "${output.status === 'retry'}"
next: execute_research
- next: synthesize
- id: synthesize
type: llm
model: synthesizer
prompt: |
Synthesize research findings:
{findings}
input:
findings: "${context.research_findings}"
next: end3. Problem Solver
states:
- id: start
type: initial
next: analyze_problem
- id: analyze_problem
type: llm
model: analyzer
prompt: |
Analyze this problem:
{problem}
Break it down into sub-problems.
input:
problem: "${input.problem}"
next: plan_solution
- id: plan_solution
type: llm
model: planner
prompt: |
Plan solution for:
{sub_problem}
Available tools:
{tools}
input:
sub_problem: "${previous.output.next_problem}"
tools: "${context.available_tools}"
next: execute_solution
- id: execute_solution
type: tool
tool: "${previous.output.tool}"
parameters: "${previous.output.parameters}"
next: evaluate_solution
- id: evaluate_solution
type: llm
model: evaluator
prompt: |
Evaluate solution:
Problem: {problem}
Solution: {solution}
Result: {result}
input:
problem: "${states.plan_solution.input.sub_problem}"
solution: "${states.execute_solution.input}"
result: "${previous.output}"
transitions:
- when: "${output.status === 'success'}"
next: analyze_problem
- when: "${output.status === 'retry'}"
next: plan_solution
- next: endAdvanced Patterns
1. Goal Decomposition
states:
- id: start
type: initial
next: decompose_goal
- id: decompose_goal
type: llm
model: decomposer
prompt: |
Break down this goal into sub-goals:
{goal}
input:
goal: "${input.goal}"
next: plan_subgoal
- id: plan_subgoal
type: llm
model: planner
prompt: |
Plan steps for sub-goal:
{sub_goal}
input:
sub_goal: "${previous.output.next_subgoal}"
next: execute_step
- id: execute_step
type: tool
tool: "${previous.output.tool}"
parameters: "${previous.output.parameters}"
next: evaluate_step
- id: evaluate_step
type: llm
model: evaluator
prompt: |
Evaluate step completion:
Step: {step}
Result: {result}
Sub-goal: {sub_goal}
input:
step: "${states.execute_step.input}"
result: "${previous.output}"
sub_goal: "${states.plan_subgoal.input.sub_goal}"
transitions:
- when: "${output.status === 'success'}"
next: plan_subgoal
- when: "${output.status === 'retry'}"
next: execute_step
- next: evaluate_goal
- id: evaluate_goal
type: llm
model: evaluator
prompt: |
Evaluate overall goal progress:
Goal: {goal}
Sub-goals: {sub_goals}
Progress: {progress}
input:
goal: "${input.goal}"
sub_goals: "${context.completed_subgoals}"
progress: "${context.progress}"
transitions:
- when: "${output.status === 'continue'}"
next: plan_subgoal
- next: end2. Adaptive Planning
states:
- id: start
type: initial
next: plan_initial
- id: plan_initial
type: llm
model: planner
prompt: |
Create initial plan for:
{goal}
Consider:
- Available resources
- Constraints
- Dependencies
input:
goal: "${input.goal}"
next: execute_step
- id: execute_step
type: tool
tool: "${previous.output.tool}"
parameters: "${previous.output.parameters}"
next: monitor_progress
- id: monitor_progress
type: llm
model: monitor
prompt: |
Monitor execution progress:
Plan: {plan}
Current Step: {step}
Results: {results}
Environment: {environment}
input:
plan: "${context.current_plan}"
step: "${states.execute_step.input}"
results: "${previous.output}"
environment: "${context.environment}"
transitions:
- when: "${output.status === 'adapt'}"
next: replan
- when: "${output.status === 'continue'}"
next: execute_step
- next: end
- id: replan
type: llm
model: planner
prompt: |
Adapt plan based on:
Original Plan: {original_plan}
Current State: {current_state}
Issues: {issues}
input:
original_plan: "${context.current_plan}"
current_state: "${context.current_state}"
issues: "${context.issues}"
next: execute_stepBest Practices
- Clear Goals: Define clear, achievable goals
- Tool Selection: Choose appropriate tools
- State Management: Maintain clear state
- Error Handling: Implement robust error handling
- Progress Monitoring: Monitor progress effectively
- Adaptability: Allow for plan adaptation
- Documentation: Document agent behavior
Common Pitfalls
- Unclear Goals: Vague or unachievable goals
- Tool Limitations: Insufficient tool capabilities
- State Confusion: Poor state management
- Error Cascades: Inadequate error handling
- Rigid Planning: Inflexible execution plans
Next Steps
- Learn about Best Practices
- Explore Examples
- Read about Testing
Last updated on