README
¶
Execution Plan Example
This example demonstrates how to use the execution plan functionality in the Agent SDK. The execution plan feature allows an agent to present a plan of actions to the user before executing them, giving the user the opportunity to approve, modify, or cancel the plan.
Overview
The execution plan functionality provides several benefits:
- Transparency: Users can see what actions the agent intends to take before they are executed.
- Control: Users can approve, modify, or cancel the plan before execution.
- Safety: Prevents the agent from taking unexpected or unwanted actions.
How It Works
- The agent generates an execution plan based on the user's request.
- The plan is presented to the user for review.
- The user can:
- Approve the plan (by typing "approve" or "yes")
- Modify the plan (by typing "modify" or "change" followed by the desired modifications)
- Cancel the plan (by typing "cancel" or "no")
- If approved, the agent executes the plan and reports the results.
Implementation Details
The execution plan functionality is implemented in the following files:
pkg/agent/execution_plan.go: Contains the core execution plan functionality.pkg/agent/agent.go: Modified to support execution plan generation and approval.
The key components are:
ExecutionPlan: A struct that represents a plan of tool executions.ExecutionStep: A struct that represents a single step in an execution plan.GenerateExecutionPlan: A method that generates an execution plan based on user input.ModifyExecutionPlan: A method that modifies an execution plan based on user feedback.ApproveExecutionPlan: A method that approves and executes a plan.
Running the Example
To run this example:
go run cmd/examples/execution_plan/main.go
The example uses a mock LLM for demonstration purposes. In a real application, you would use a real LLM provider like OpenAI.
Example Conversation
Here's an example of how a conversation might flow:
User: What's the weather in New York and convert the temperature to Celsius?
Agent: I've created an execution plan for your request:
# Execution Plan: Search for weather information and calculate temperature conversion
## Step 1: Search for current weather information
Tool: search
Input: current weather in New York
Parameters:
- param1: weather
## Step 2: Convert temperature from Fahrenheit to Celsius
Tool: calculator
Input: convert 75F to C
Parameters:
Would you like to approve, modify, or cancel this plan?
User: modify I want to use the weather tool directly instead of search
Agent: I've updated the execution plan based on your feedback:
# Execution Plan: Search for weather information and calculate temperature conversion
## Step 1: Get current weather information directly
Tool: weather
Input: New York
Parameters:
- param1: New York
## Step 2: Convert temperature from Fahrenheit to Celsius
Tool: calculator
Input: convert 75F to C
Parameters:
Do you approve this plan? You can modify it further if needed.
User: approve
Agent: Executing the approved plan...
Step 1: Get current weather information directly
Result: Executed weather with input: New York
Step 2: Convert temperature from Fahrenheit to Celsius
Result: Executed calculator with input: convert 75F to C
Customization
You can customize the execution plan functionality by:
- Setting
requirePlanApprovaltofalseto disable execution plan approval. - Modifying the prompt templates in
createExecutionPlanPromptandModifyExecutionPlan. - Extending the
ExecutionPlanandExecutionStepstructs with additional fields.
Integration with Your Application
To integrate execution plan functionality into your application:
- Create an agent with
WithRequirePlanApproval(true). - Handle user responses to execution plans in your application's UI.
- Call the appropriate methods (
ApproveExecutionPlan,ModifyExecutionPlan) based on user responses.
Documentation
¶
There is no documentation for this package.