API 参考 / API Reference
Agno-Go v1.0 的完整 API 参考文档。
核心模块 / Core Modules
- Agent - 自主式 AI 智能体 / Autonomous AI agents
- Team - 多智能体协作 / Multi-agent collaboration
- Workflow - 基于步骤的编排 / Step-based orchestration
- Models - LLM 提供商集成 / LLM provider integrations
- Tools - 内置和自定义工具 / Built-in and custom tools
- Memory - 对话历史管理 / Conversation history management
- Types - 核心类型和错误 / Core types and errors
- AgentOS Server - 生产环境 HTTP 服务器 / Production HTTP server
快速链接 / Quick Links
Agent
go
import "github.com/rexleimo/agno-Go/pkg/agno/agent"
agent.New(config) (*Agent, error)
agent.Run(ctx, input) (*RunOutput, error)
agent.ClearMemory()
Team
go
import "github.com/rexleimo/agno-Go/pkg/agno/team"
team.New(config) (*Team, error)
team.Run(ctx, input) (*RunOutput, error)
// 模式 / Modes: Sequential, Parallel, LeaderFollower, Consensus
Workflow
go
import "github.com/rexleimo/agno-Go/pkg/agno/workflow"
workflow.New(config) (*Workflow, error)
workflow.Run(ctx, input) (*RunOutput, error)
// 原语 / Primitives: Step, Condition, Loop, Parallel, Router
Models
go
import (
"github.com/rexleimo/agno-Go/pkg/agno/models/openai"
"github.com/rexleimo/agno-Go/pkg/agno/models/anthropic"
"github.com/rexleimo/agno-Go/pkg/agno/models/ollama"
)
openai.New(modelID, config) (*OpenAI, error)
anthropic.New(modelID, config) (*Anthropic, error)
ollama.New(modelID, config) (*Ollama, error)
Tools
go
import (
"github.com/rexleimo/agno-Go/pkg/agno/tools/calculator"
"github.com/rexleimo/agno-Go/pkg/agno/tools/http"
"github.com/rexleimo/agno-Go/pkg/agno/tools/file"
)
calculator.New() *Calculator
http.New(config) *HTTP
file.New(config) *File
常见模式 / Common Patterns
错误处理 / Error Handling
go
import "github.com/rexleimo/agno-Go/pkg/agno/types"
output, err := agent.Run(ctx, input)
if err != nil {
switch {
case errors.Is(err, types.ErrInvalidInput):
// 处理无效输入 / Handle invalid input
case errors.Is(err, types.ErrRateLimit):
// 处理速率限制 / Handle rate limit
default:
// 处理其他错误 / Handle other errors
}
}
Context 管理 / Context Management
go
import (
"context"
"time"
)
// 带超时 / With timeout
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
output, err := agent.Run(ctx, input)
并发智能体 / Concurrent Agents
go
var wg sync.WaitGroup
for i := 0; i < 10; i++ {
wg.Add(1)
go func(id int) {
defer wg.Done()
ag, _ := agent.New(config)
output, _ := ag.Run(ctx, input)
fmt.Printf("Agent %d: %s\n", id, output.Content)
}(i)
}
wg.Wait()
类型定义 / Type Definitions
核心类型 / Core Types
go
// 消息类型 / Message types
type Message struct {
Role MessageRole
Content string
Name string
}
// 运行输出 / Run output
type RunOutput struct {
Content string
Messages []Message
Metadata map[string]interface{}
}
// 模型响应 / Model response
type ModelResponse struct {
Content string
ToolCalls []ToolCall
FinishReason string
}
AgentOS Server API
生产环境部署的 REST API 端点 / REST API endpoints for production deployment:
bash
# 健康检查 / Health check
GET /health
# 列出智能体 / List agents
GET /api/v1/agents
# 运行智能体 / Run agent
POST /api/v1/agents/{agent_id}/run
# 创建会话 / Create session
POST /api/v1/sessions
# 获取会话 / Get session
GET /api/v1/sessions/{session_id}
OpenAPI 规范 / OpenAPI Specification
完整的 OpenAPI 3.0 规范文档 / Complete OpenAPI 3.0 specification available:
示例 / Examples
查看仓库中的工作示例 / See working examples in the repository:
包文档 / Package Documentation
完整的 Go 包文档可在 pkg.go.dev 上查看 / Full Go package documentation is available on pkg.go.dev: