|
| 1 | +# iteragent |
| 2 | + |
| 3 | +`iteragent` is a lightweight, zero-dependency Go agent framework for building LLM-powered applications. It provides a unified interface to multiple LLM providers, tool-use capabilities, streaming support, context compaction, and an extensible plugin system via MCP and OpenAPI. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Unified Provider Interface** — Switch between Anthropic, OpenAI, Azure OpenAI, Google Gemini, AWS Bedrock, NVIDIA, OpenAI-compatible APIs, and OpenAI Responses API with a single interface |
| 8 | +- **Streaming Support** — Real-time token-by-token streaming via SSE for all supported providers |
| 9 | +- **Tool Use** — Built-in tools (shell, file I/O, search, git operations, test execution) plus MCP and OpenAPI tool discovery |
| 10 | +- **Context Compaction** — Automatic 3-tier context management to handle long conversations within token limits |
| 11 | +- **Retry Logic** — Smart retry with exponential backoff for rate limits and transient errors |
| 12 | +- **Zero Dependencies** — Uses only the Go standard library — no supply-chain risk from third-party packages |
| 13 | +- **Concurrent Execution** — Safe parallel tool execution with configurable strategies (sequential, parallel, batched) |
| 14 | +- **Sub-Agents** — Decompose tasks into specialized sub-agents with isolated tool sets |
| 15 | + |
| 16 | +## Installation |
| 17 | + |
| 18 | +```bash |
| 19 | +go get github.com/GrayCodeAI/iteragent |
| 20 | +``` |
| 21 | + |
| 22 | +## Quick Start |
| 23 | + |
| 24 | +```go |
| 25 | +package main |
| 26 | + |
| 27 | +import ( |
| 28 | + "fmt" |
| 29 | + "github.com/GrayCodeAI/iteragent" |
| 30 | +) |
| 31 | + |
| 32 | +func main() { |
| 33 | + agent := iteragent.New( |
| 34 | + iteragent.NewGemini(iteragent.GeminiConfig{ |
| 35 | + Model: "gemini-2.0-flash", |
| 36 | + APIKey: "YOUR_API_KEY", |
| 37 | + }), |
| 38 | + nil, |
| 39 | + nil, |
| 40 | + ) |
| 41 | + |
| 42 | + response, err := agent.Run( |
| 43 | + context.Background(), |
| 44 | + "You are a helpful assistant.", |
| 45 | + "What is the capital of France?", |
| 46 | + ) |
| 47 | + if err != nil { |
| 48 | + fmt.Println("Error:", err) |
| 49 | + return |
| 50 | + } |
| 51 | + fmt.Println(response) |
| 52 | +} |
| 53 | +``` |
| 54 | + |
| 55 | +## Providers |
| 56 | + |
| 57 | +| Provider | Function | Environment Variable for API Key | |
| 58 | +|----------|----------|----------------------------------| |
| 59 | +| Anthropic | `NewAnthropic(AntropicConfig{...})` | `ANTHROPIC_API_KEY` | |
| 60 | +| OpenAI | `NewOpenAICompat(OpenAICompatConfig{...})` | `OPENAI_API_KEY` | |
| 61 | +| Azure OpenAI | `NewAzureOpenAI(AzureOpenAIConfig{...})` | — | |
| 62 | +| Google Gemini | `NewGemini(GeminiConfig{...})` | `GEMINI_API_KEY` | |
| 63 | +| AWS Bedrock | `NewBedrock(BedrockConfig{...})` | — | |
| 64 | +| NVIDIA | `NewOpenAICompat(OpenAICompatConfig{...})` | `NVIDIA_API_KEY` | |
| 65 | +| OpenAI Responses | `NewOpenAIResponses(OpenAIResponsesConfig{...})` | — | |
| 66 | + |
| 67 | +Alternatively, use `iteragent.NewProvider(name, apiKey)` to select via environment variable: |
| 68 | + |
| 69 | +```bash |
| 70 | +ITERATE_PROVIDER=gemini GEMINI_API_KEY=xxx go run main.go |
| 71 | +``` |
| 72 | + |
| 73 | +## Architecture |
| 74 | + |
| 75 | +- **Agent** — Core reasoning loop that manages message history, tool execution, and context compaction |
| 76 | +- **Provider** — LLM backend interface with `Complete` and optional `CompleteStream` (TokenStreamer) methods |
| 77 | +- **Tools** — Callable functions the agent can invoke (shell, file read/write, git, search, etc.) |
| 78 | +- **Context Compaction** — Automatically compresses conversation history when token limits are approached |
| 79 | +- **MCP** — Connect to external tool servers via Model Context Protocol |
| 80 | +- **OpenAPI** — Auto-generate tools from OpenAPI specifications |
| 81 | + |
| 82 | +## Building and Testing |
| 83 | + |
| 84 | +```bash |
| 85 | +go build ./... |
| 86 | +go test ./... |
| 87 | +go test -race ./... |
| 88 | +``` |
| 89 | + |
| 90 | +## License |
| 91 | + |
| 92 | +MIT — see [LICENSE](LICENSE) |
0 commit comments