goagent

module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 14, 2026 License: Apache-2.0

README

GoAgent

GoAgent is a generic multi-agent framework implemented in Go, supporting multi-agent collaboration, memory management, and tool invocation.

Architecture Diagram

archs

Embedding Gateway Service (FastAPI)

The Embedding Service is a standalone vector embedding service for GoAgent, supporting multiple backends:

embedding

Embedding Service Features:

  • High Performance: Supports Ollama local deployment and SentenceTransformers cloud deployment
  • Smart Caching: Redis cache + text normalization to avoid cache misses
  • Batch Processing: Supports batch vector generation for improved efficiency
  • Auto Normalization: Vectors automatically normalized to unit vectors for accurate cosine similarity
  • Health Check: Built-in health check endpoint

Configuration File: services/embedding/.env

BACKEND_TYPE=ollama              # Backend type: ollama / transformers
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=qwen3-embedding:0.6b
MODEL_NAME=qwen3-embedding:0.6b
EMBEDDING_DIM=1024
REDIS_URL=redis://localhost:6379
CACHE_TTL=86400
HOST=0.0.0.0
PORT=8000

Code Locations:

  • services/embedding/app.py - Service main program
  • services/embedding/config.py - Configuration management
  • internal/storage/postgres/embedding/client.go - Go client
Memory Distillation model

distillation

Tech Stack

Core Technologies
  • Language: Go 1.26+
  • Database: PostgreSQL 15+ with pgvector extension
  • Concurrency: errgroup, sync
  • Protocol: Custom AHP Protocol
  • Embedding Service: FastAPI + Ollama/SentenceTransformers
  • Cache: Redis
Main Components
Component Purpose Code Location
Agent System Leader/Sub Agent collaboration internal/agents/
Protocol Layer Inter-agent communication and heartbeat internal/protocol/ahp/
Memory System Session, task, and distilled memory internal/memory/
Storage Layer PostgreSQL + pgvector internal/storage/postgres/
Tool System Tool registry and invocation internal/tools/
Workflow Engine DAG workflow orchestration internal/workflow/engine/
Embedding Service Vector embedding generation services/embedding/
Dependencies
  • github.com/jackc/pgx/v5 - PostgreSQL driver
  • github.com/google/uuid - UUID generation
  • github.com/stretchr/testify - Testing framework
  • golang.org/x/sync - Concurrent extensions
  • gopkg.in/yaml.v3 - YAML parsing
  • fastapi - Embedding service framework
  • redis - Cache support

Configuration

1. LLM Configuration

Config File: examples/travel/config.yaml

llm:
  provider: openrouter        # LLM provider: openai / ollama / openrouter
  api_key: ""                  # API Key (recommended: use env var OPENROUTER_API_KEY)
  base_url: https://openrouter.ai/api/v1
  model: meta-llama/llama-3.1-8b-instruct
  timeout: 60                  # Request timeout (seconds)
  max_tokens: 2048              # Max response tokens

Code Location: internal/llm/client.go:80-100

2. Agent Configuration
agents:
  leader:
    id: leader-travel
    max_steps: 10              # Max execution steps
    max_parallel_tasks: 4      # Max parallel tasks
    enable_cache: true          # Enable caching

  sub:
    - id: agent-destination
      type: destination         # Agent type: destination/food/hotel/itinerary
      triggers: [destination]   # Trigger keywords
      max_retries: 3             # Max retry attempts
      timeout: 30                # Timeout (seconds)

Code Location: internal/agents/leader/agent.go:30-50

3. Database Configuration
storage:
  enabled: true               # Enable PostgreSQL storage
  type: postgres
  host: localhost
  port: 5433                # Docker default port is 5433
  user: postgres
  password: postgres
  database: goagent
  
  pgvector:
    enabled: true             # Enable pgvector
    dimension: 1024           # Vector dimension

Code Location: internal/storage/postgres/pool.go:35-50

4. Embedding Service Configuration
embedding:
  service_url: http://localhost:8000    # Embedding service address
  model: qwen3-embedding:0.6b          # Model name
  dimension: 1024                       # Vector dimension
  timeout: 30                           # Request timeout (seconds)

Code Location: internal/storage/postgres/embedding/client.go:30-50

5. Memory Configuration
memory:
  enabled: true               # Enable memory system
  enable_distillation: true   # Enable memory distillation
  distillation_threshold: 3   # Trigger distillation every N rounds

Code Location: examples/knowledge-base/main.go:750-760

6. Retrieval Configuration
knowledge:
  chunk_size: 1000             # Document chunk size
  chunk_overlap: 100            # Chunk overlap
  top_k: 10                    # Return top K results
  min_score: 0.6               # Minimum similarity threshold

Code Location: internal/storage/postgres/repositories/knowledge_repository.go:100-120

Quick Start

1. Set Environment
# Set API Key (recommended: use environment variable)
export OPENROUTER_API_KEY="your-api-key"

# Or set in config file (not recommended)
2. Start Database (Optional, for persistence)
# Quick start PostgreSQL + pgvector with Docker
docker run -d \
  --name goagent-db \
  -e POSTGRES_PASSWORD=postgres \
  -e POSTGRES_DB=goagent \
  -p 5433:5432 \
  pgvector/pgvector:pg15

# Verify connection
docker exec -it goagent-db psql -U postgres -d goagent -c "SELECT version();"
3. Start Embedding Service (for vector retrieval)
# Navigate to embedding service directory
cd services/embedding

# Run setup script (install dependencies and model)
./setup.sh

# Start service
./start.sh

# Verify service
curl http://localhost:8000/health
4. Run Examples
# Travel planning example
cd examples/travel
go run main.go

# Knowledge base Q&A example (requires database + embedding service)
cd examples/knowledge-base
go run main.go --save README.md  # Import document
go run main.go --chat             # Start Q&A

Project Structure

goagent/
├── examples/               # Example applications
│   ├── travel/              # Travel planning
│   ├── knowledge-base/       # Knowledge base Q&A
│   └── simple/              # Simple example
├── internal/                # Core implementation
│   ├── agents/              # Agent system
│   │   ├── base/            # Agent base interfaces
│   │   ├── leader/          # Leader Agent
│   │   └── sub/             # Sub Agent
│   ├── protocol/             # AHP protocol
│   ├── storage/              # PostgreSQL + pgvector
│   ├── memory/               # Memory system
│   └── workflow/             # Workflow engine
├── services/                # Standalone services
│   └── embedding/           # Embedding service
│       ├── app.py           # FastAPI service
│       ├── config.py        # Configuration management
│       └── requirements.txt # Python dependencies
├── api/                     # API layer
│   ├── service/             # Service interfaces
│   └── client/              # Client
└── docs/                    # Documentation

Documentation

Migration Guide (v0.2)

Breaking Changes
  1. TaskPlanner.Plan() signature changed

    • Before: Plan(ctx, profile) (2 args)
    • After: Plan(ctx, profile, inputText) (3 args)
    • Fix: Add inputText parameter to all Plan() calls.
  2. NewResultAggregator() requires sortBy parameter

    • Before: NewResultAggregator(enableDedupe, maxItems)
    • After: NewResultAggregator(enableDedupe, maxItems, sortBy)
    • Fix: Add leader.SortByNone (or SortByPriority / SortByCreatedAt) as third argument.
  3. Fashion-specific constants removed

    • Removed: AgentTypeShoes, AgentTypeHead, AgentTypeAccessory, StyleCasual, StyleFormal, StyleStreet, OccasionDaily, OccasionParty, OccasionDate
    • Fix: Replace with models.StyleTag("...") and models.Occasion("...") string types.
  4. Domain types renamed (internal/tools/resources/types/)

    • FashionFiltersResourceFilters
    • FashionItemResourceItem
    • AgentProfileAgentUserProfile
    • AgentRecommendationTaskRecommendation
    • OutfitSuggestionSuggestion
    • AgentTrendTrend
  5. Validation default schema type changed

    • Before: "fashion"
    • After: "default"
    • Fix: Update config if explicitly setting validation.schema_type.

Examples

Development Guide

Running Tests
# Run all tests
go test ./...

# Run tests for specific package
go test ./internal/agents/...

# Run tests with coverage
go test -cover ./...
Building Project
# Build examples
go build -o bin/simple ./examples/simple
go build -o bin/travel ./examples/travel

# Build CLI tools
go build -o bin/migrate ./cmd/migrate_goagent
Code Standards
# Format code
go fmt ./...

# Run linter
golangci-lint run

Directories

Path Synopsis
api
Package api provides legacy unified client interface for GoAgent framework.
Package api provides legacy unified client interface for GoAgent framework.
agent
Package agent provides error definitions for agent operations.
Package agent provides error definitions for agent operations.
client
Package client provides client interface for GoAgent API.
Package client provides client interface for GoAgent API.
core
Package core provides core abstractions for agent operations.
Package core provides core abstractions for agent operations.
errors
Package errors provides unified error definitions for API layer.
Package errors provides unified error definitions for API layer.
experience
Package experience provides experience conflict resolution service.
Package experience provides experience conflict resolution service.
memory
Package memory provides API abstractions for memory distillation operations.
Package memory provides API abstractions for memory distillation operations.
retrieval
Package retrieval provides error definitions for retrieval operations.
Package retrieval provides error definitions for retrieval operations.
service/agent
Package agent provides error definitions for agent service.
Package agent provides error definitions for agent service.
service/graph
Package graph provides YAML configuration parsing for graph workflows.
Package graph provides YAML configuration parsing for graph workflows.
service/llm
Package llm provides error definitions for LLM service.
Package llm provides error definitions for LLM service.
service/memory
Package memory provides error definitions for memory service.
Package memory provides error definitions for memory service.
service/retrieval
Package retrieval provides error definitions for retrieval service.
Package retrieval provides error definitions for retrieval service.
cmd
check_rls command
migrate_goagent command
Package main provides database setup for goagent knowledge base.
Package main provides database setup for goagent knowledge base.
setup_test_db command
Package main provides database setup for testing.
Package main provides database setup for testing.
examples
capability-demo command
devagent command
devagent_newapi command
experience-bilingual command
Package main provides a bilingual test for experience distillation with database storage and retrieval.
Package main provides a bilingual test for experience distillation with database storage and retrieval.
graph_demo/agent command
Package main demonstrates agent integration with graph.
Package main demonstrates agent integration with graph.
graph_demo/basic command
Package main demonstrates basic graph usage.
Package main demonstrates basic graph usage.
graph_demo/conditional command
Package main demonstrates conditional branching in graphs.
Package main demonstrates conditional branching in graphs.
graph_demo/integration command
Package main demonstrates a real-world integration example using the graph system.
Package main demonstrates a real-world integration example using the graph system.
graph_demo/scheduler command
Package main demonstrates different scheduling strategies.
Package main demonstrates different scheduling strategies.
knowledge-base command
openrouter command
simple command
simple_newapi command
travel command
internal
experience
Package experience provides experience conflict resolution service.
Package experience provides experience conflict resolution service.
llm
Package llm provides LLM client functionality for various providers.
Package llm provides LLM client functionality for various providers.
memory
Package memory provides unified memory management for the StyleAgent framework.
Package memory provides unified memory management for the StyleAgent framework.
memory/distillation
Package distillation provides memory distillation functionality for agent experience extraction.
Package distillation provides memory distillation functionality for agent experience extraction.
storage/postgres
Package postgres provides PostgreSQL database operations for the storage system.
Package postgres provides PostgreSQL database operations for the storage system.
storage/postgres/adapters
Package adapters provides format conversion layer for storage operations.
Package adapters provides format conversion layer for storage operations.
storage/postgres/embedding
nolint: errcheck // Operations may ignore return values
nolint: errcheck // Operations may ignore return values
storage/postgres/models
Package models defines data structures for the storage system.
Package models defines data structures for the storage system.
storage/postgres/repositories
Package repositories provides data access layer for storage system.
Package repositories provides data access layer for storage system.
storage/postgres/services
Package services provides retrieval services for the storage system.
Package services provides retrieval services for the storage system.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL