README
¶
API Server Example
This example demonstrates how to use the execution plan functionality in an API server. It shows how to implement a workflow similar to the one described in the bash script, where users can:
- Start a conversation with the agent
- Provide requirements
- Review and modify execution plans
- Approve plans for execution
- Monitor execution
- Discuss results
Overview
The API server provides the following endpoints:
POST /api/v1/chat: Send messages to the agentGET /api/v1/tasks/{id}: Get details of a specific taskGET /api/v1/tasks: List all tasks
How It Works
- The user starts a conversation by sending a message to the
/api/v1/chatendpoint. - The agent generates an execution plan based on the user's request.
- The plan is presented to the user for review.
- The user can modify the plan by sending modification requests to the
/api/v1/chatendpoint. - The user can approve the plan by sending an approval message to the
/api/v1/chatendpoint. - The agent executes the plan and reports the results.
- The user can check the status of the task using the
/api/v1/tasks/{id}endpoint.
Implementation Details
The API server is implemented using the standard Go HTTP package. It maintains a map of agents for each user and a map of conversations. When a user sends a message, the server:
- Gets or creates a conversation for the user
- Gets or creates an agent for the user
- Processes the message with the agent
- Returns the agent's response along with any task IDs
If the agent generates an execution plan, the task ID is included in the response. The user can then:
- Get details of the plan using the
/api/v1/tasks/{id}endpoint - Modify the plan by sending a modification request to the
/api/v1/chatendpoint - Approve the plan by sending an approval message to the
/api/v1/chatendpoint
Running the Example
To run this example:
go run cmd/examples/api_server/main.go
The server will listen on port 8080.
Example Workflow
Here's an example of how to use the API server:
- Start a conversation:
curl -X POST "http://localhost:8080/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{
"user_id": "user123",
"message": "I need to deploy a new web application on AWS with a load balancer and auto-scaling."
}'
- Provide requirements:
curl -X POST "http://localhost:8080/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{
"conversation_id": "CONVERSATION_ID",
"user_id": "user123",
"message": "It's a Node.js application. I want to deploy it in us-west-2. Auto-scaling should be based on CPU usage (>70%)."
}'
- Check the task:
curl -X GET "http://localhost:8080/api/v1/tasks/TASK_ID"
- Modify the plan:
curl -X POST "http://localhost:8080/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{
"conversation_id": "CONVERSATION_ID",
"user_id": "user123",
"message": "I'd like to make a few changes. Can we use t3.medium instances instead? Also, I want to add CloudFront for content delivery."
}'
- Approve the plan:
curl -X POST "http://localhost:8080/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{
"conversation_id": "CONVERSATION_ID",
"user_id": "user123",
"message": "I approve the plan. Please proceed with the execution."
}'
- Check the task status:
curl -X GET "http://localhost:8080/api/v1/tasks/TASK_ID"
- Discuss results:
curl -X POST "http://localhost:8080/api/v1/chat" \
-H "Content-Type: application/json" \
-d '{
"conversation_id": "CONVERSATION_ID",
"user_id": "user123",
"message": "Great! The deployment is complete. How can I access my application now?"
}'
Customization
You can customize the API server by:
- Adding authentication and authorization
- Implementing persistent storage for conversations and tasks
- Adding more endpoints for specific operations
- Integrating with real LLM providers and tools
- Adding error handling and logging
Integration with Your Application
To integrate this API server with your application:
- Use the API endpoints to communicate with the agent
- Store conversation IDs and task IDs in your application
- Display execution plans to users and allow them to modify and approve them
- Monitor task execution and display results to users
Documentation
¶
There is no documentation for this package.
Click to show internal directories.
Click to hide internal directories.