This example demonstrates the fundamental usage of the Agent Framework.
- Framework initialization - Setting up storage and LLM provider
- Agent creation - Creating an agent with configuration
- Agent activation - Updating agent status
- Agent execution - Running queries through the agent
- Metrics retrieval - Getting execution statistics
- Activity tracking - Viewing execution history
- Agent listing - Querying available agents
- Go 1.25 or higher
- OpenAI API key
Set your OpenAI API key:
export OPENAI_API_KEY="your-api-key-here"cd pkg/agentframework/examples/basic
go run main.go🤖 Agent Framework - Basic Example
===================================
1. Initializing framework...
✓ Framework initialized
2. Creating agent...
✓ Agent created: My First Agent (ID: xxx-xxx-xxx)
- Behavior: default
- Status: draft
3. Activating agent...
✓ Agent activated: active
4. Executing agent with questions...
Question 1: What is 2 + 2?
Answer: 2 + 2 equals 4.
Tokens used: 15
Question 2: Explain quantum computing in one sentence.
Answer: Quantum computing uses quantum bits...
Tokens used: 42
...
5. Retrieving agent metrics...
✓ Metrics retrieved:
- Total executions: 3
- Successful: 3
- Failed: 0
- Avg execution time: 1234.56ms
6. Retrieving recent activities...
✓ Found 3 activities:
1. Action: execute | Status: success | Duration: 1200ms
2. Action: execute | Status: success | Duration: 1300ms
3. Action: execute | Status: success | Duration: 1100ms
7. Listing all agents...
✓ Found 1 agent(s):
1. My First Agent (xxx-xxx-xxx) - Status: active
✅ Example completed successfully!
The framework is configured using the options pattern:
framework := core.NewFramework(
core.WithStorage(storage.NewInMemory()),
core.WithLLMProvider(llm.NewOpenAI(apiKey)),
)Agents are configured with:
- Name & Description - Identification
- BehaviorType - How the agent processes input/output (default: "default")
- Config - LLM settings (model, temperature, max tokens, personality)
- Capabilities - What the agent can do
- Status - Lifecycle state (draft, active, inactive, archived)
- Input is processed by the agent's behavior
- System prompt is generated based on agent configuration
- LLM processes the request
- Output is processed by the agent's behavior
- Activity is recorded and metrics are updated
- Try the with_tools example to see tool integration
- Try the custom_behavior example to create custom agent behaviors
- Explore the framework documentation in
pkg/agentframework/README.md