This example demonstrates the agent-go runtime with file operation tools.
The FileOps example showcases:
- Tool Registration: Four file operation tools with proper annotations
- State-Driven Execution: Tools are only available in appropriate states
- Policy Enforcement: Tool eligibility and state transitions
- Scripted Planner: Deterministic execution for testing/demo
- Budget Management: Limiting tool calls
| Tool | Description | Risk Level | Allowed States |
|---|---|---|---|
read_file |
Reads file content | Low | explore, act, validate |
write_file |
Writes content to a file | Medium | act |
delete_file |
Deletes a file | High (requires approval) | act |
list_dir |
Lists directory contents | Low | explore, act, validate |
intake → explore → decide → act → validate → done
The example follows this workflow:
- Intake: Start state
- Explore: List directory contents (read-only)
- Decide: Determine action to take
- Act: Create a file (side effects allowed)
- Validate: Read back and verify file
- Done: Complete with result
# From project root
go run ./example/fileops
# Or using make
make example=== FileOps Agent Example ===
Workspace: /tmp/fileops-example-xxxxx
--- Run Results ---
Run ID: run-xxxxxxxxx
Status: completed
Final State: done
Duration: Xms
Result: {
"file": "hello.txt",
"status": "created"
}
--- Evidence Trail ---
1. [tool] list_dir
Output: {"files": [], "count": 0}
2. [tool] write_file
Output: {"bytes_written": 19, "created": true}
3. [tool] read_file
Output: {"content": "Hello, Agent World!", "size": 19}
4. [tool] list_dir
Output: {"files": [{"name": "hello.txt", ...}], "count": 1}
--- File Verification ---
File path: /tmp/fileops-example-xxxxx/hello.txt
Content: Hello, Agent World!
=== Example completed successfully! ===
api.Annotations{
ReadOnly: true, // No side effects
Destructive: false, // Doesn't destroy data
Idempotent: true, // Same result if called multiple times
Cacheable: true, // Results can be cached
RiskLevel: api.RiskLow,
}eligibility := api.NewToolEligibility()
// Read-only tools in explore
eligibility.Allow(agent.StateExplore, "read_file")
eligibility.Allow(agent.StateExplore, "list_dir")
// All tools in act state
eligibility.Allow(agent.StateAct, "write_file")
eligibility.Allow(agent.StateAct, "delete_file")planner := api.NewScriptedPlanner(
api.ScriptStep{
ExpectState: agent.StateIntake,
Decision: api.NewTransitionDecision(agent.StateExplore, "Begin"),
},
api.ScriptStep{
ExpectState: agent.StateExplore,
Decision: api.NewCallToolDecision("list_dir", input, "reason"),
},
// ... more steps
)api.WithBudgets(map[string]int{
"tool_calls": 10, // Max 10 tool calls per run
})The tools implement path traversal protection:
func isSubPath(base, path string) bool {
// Ensures paths stay within the workspace directory
}To add more tools:
- Define input/output types
- Create the tool with
api.NewToolBuilder() - Set appropriate annotations
- Register with the registry
- Configure eligibility for each state
- Customer Support Agent - Support ticket handling with KB search
- DevOps Monitor Agent - Infrastructure monitoring with incident response
- Website Demo - Interactive visualization of this agent
- Documentation - Full API documentation
- GitHub Repository - Source code and issues