The agent package provides an AI agent system that can autonomously process tasks using LLM services, manage tasks through a task management system, and create pull requests with solutions.
The agent system consists of:
package main import ( "log" "time" "github.com/iomodo/staff/agent" "github.com/iomodo/staff/git" "github.com/iomodo/staff/llm" "github.com/iomodo/staff/tm" "github.com/iomodo/staff/tm/git_tm" ) func main() { // Create git interface for task management gitInterface := git.DefaultGit("./tasks-repo") // Create task manager taskManager := git_tm.NewGitTaskManager(gitInterface, "./tasks-repo") // Create LLM configuration llmConfig := llm.Config{ Provider: llm.ProviderOpenAI, APIKey: "your-openai-api-key-here", BaseURL: "https://api.openai.com/v1", Timeout: 30 * time.Second, } // Create agent configuration config := agent.AgentConfig{ Name: "backend-engineer-1", Role: "Backend Engineer", GitUsername: "backend-agent", GitEmail: "backend-agent@company.com", WorkingDir: "./workspace", LLMProvider: llm.ProviderOpenAI, LLMModel: "gpt-4", LLMConfig: llmConfig, SystemPrompt: `You are a skilled backend engineer. Your role is to: 1. Analyze tasks and provide technical solutions 2. Write clean, maintainable code 3. Consider performance, security, and scalability 4. Provide clear documentation for your solutions 5. Follow best practices and coding standards`, TaskManager: taskManager, GitRepoPath: "./code-repo", GitRemote: "origin", GitBranch: "main", } // Create agent agent, err := agent.NewAgent(config) if err != nil { log.Fatalf("Failed to create agent: %v", err) } // Run the agent if err := agent.Run(); err != nil { log.Fatalf("Agent failed: %v", err) } }
// Create a task for the agent to process ctx := context.Background() task, err := taskManager.CreateTask(ctx, &tm.TaskCreateRequest{ Title: "Implement user authentication API", Description: "Create a REST API endpoint for user authentication with JWT tokens. Include login, logout, and token refresh functionality.", OwnerID: "backend-engineer-1", // Must match agent name Priority: tm.PriorityHigh, }) if err != nil { log.Fatalf("Failed to create task: %v", err) }
The AgentConfig struct contains all configuration for an agent:
type AgentConfig struct { Name string // Agent identifier Role string // Agent role (e.g., "Backend Engineer") GitUsername string // Git username for commits GitEmail string // Git email for commits WorkingDir string // Working directory for files // LLM Configuration LLMProvider llm.Provider // LLM provider type LLMModel string // Model name (e.g., "gpt-4") LLMConfig llm.Config // LLM provider configuration // System prompt for the agent SystemPrompt string // Instructions for the LLM // Task Manager Configuration TaskManager tm.TaskManager // Task management interface // Git Configuration GitRepoPath string // Path to git repository GitRemote string // Remote name (usually "origin") GitBranch string // Default branch name }
System prompts define the agent's behavior and expertise. Here are some examples:
You are a skilled backend engineer. Your role is to: 1. Analyze tasks and provide technical solutions 2. Write clean, maintainable code 3. Consider performance, security, and scalability 4. Provide clear documentation for your solutions 5. Follow best practices and coding standards When responding to tasks, provide: - Detailed technical analysis - Code examples where appropriate - Implementation considerations - Testing recommendations - Documentation suggestions
You are a frontend engineer. Focus on: - User interface design and implementation - React/Vue/Angular development - Responsive design and accessibility - Performance optimization - User experience best practices
You are a product manager. Focus on: - Product strategy and roadmap - User research and requirements gathering - Feature prioritization and planning - Stakeholder communication - Product documentation and specifications
The agent runs in an infinite loop that:
For each task, the agent:
task/{task-id}-{clean-title}Solutions are formatted as markdown files containing:
You can run multiple agents with different roles:
// Create agents with different roles agents := []agent.AgentConfig{ { Name: "backend-engineer-1", Role: "Backend Engineer", // ... backend configuration }, { Name: "frontend-engineer-1", Role: "Frontend Engineer", // ... frontend configuration }, { Name: "product-manager-1", Role: "Product Manager", // ... product manager configuration }, } // Start all agents for _, config := range agents { agent, err := agent.NewAgent(config) if err != nil { log.Printf("Failed to create agent %s: %v", config.Name, err) continue } go func(agent *agent.Agent, name string) { log.Printf("Starting agent: %s", name) if err := agent.Run(); err != nil { log.Printf("Agent %s stopped with error: %v", name, err) } }(agent, config.Name) }
The agent includes robust error handling:
Run the tests with:
go test ./server/agent/...
The test suite includes:
The agent package depends on:
github.com/iomodo/staff/llm - LLM service interfacegithub.com/iomodo/staff/tm - Task management interfacegithub.com/iomodo/staff/git - Git operations interfaceSee example.go for complete working examples:
ExampleAgent() - Single agent setupExampleMultipleAgents() - Multiple agents with different rolesOwnerID to the agent's name