Agents
Agents are the core building block of GoFlow. An agent takes a task, reasons about it, uses tools, and returns a result.
Basic Agent
The agent.New() function takes an LLM (the AI model) and a tool registry (what the agent can do). The agent then uses a ReAct-style loop: Reason → Act → Observe → Repeat until it has the answer.
Configuration
Each option customizes agent behavior:
| Option | What it does |
|---|---|
WithMaxIterations | Prevents infinite loops by capping reasoning steps |
WithTimeout | Kills the agent if it takes too long |
WithVerbose | Prints each thought/action for debugging |
WithSystemPrompt | Sets the agent's personality and instructions |
Agent Options
| Option | Description | Default |
|---|---|---|
WithMaxIterations | Maximum reasoning steps | 10 |
WithTimeout | Overall execution timeout | 5m |
WithVerbose | Enable step logging | false |
WithSystemPrompt | Custom system prompt | (built-in) |
WithMemory | Enable memory/context | nil |
Lifecycle Hooks
Monitor agent execution with hooks:
Hooks let you observe and log everything the agent does without modifying its behavior. This is invaluable for debugging and monitoring in production.
Result Structure
The RunResult gives you complete visibility into the agent's work:
- Output - The final answer to present to the user
- Steps - Every thought and action the agent took
- ToolCalls - Which tools were invoked and with what inputs
- Duration - Total execution time for performance monitoring
Streaming
Stream agent output in real-time:
Streaming is essential for responsive UIs. Instead of waiting for the complete response, you display tokens as they arrive, making the agent feel faster and more interactive.
Agent with Memory
Persist context across runs:
Without memory, each Run() is independent. With memory, the agent builds up context over multiple interactions, enabling conversational experiences.
Custom Agent Types
Create specialized agents:
Different agents can have different tools and prompts. A research agent might have web search capabilities, while a code agent might have file system access. Keep agents focused on specific domains for better results.
