Agent Go SDK

repository·main·Indexed 20 days ago

https://github.com/ingenimax/agent-sdk-go

A framework for building production-ready AI agents in Go, featuring multi-LLM support (OpenAI, Anthropic, Vertex AI, Ollama, vLLM), modular tools, memory management, and observability. It includes a CLI for running queries, interactive chat, and executing predefined tasks via YAML configurations. The SDK supports the Model Context Protocol (MCP) for external server integration and an Agent-to-Agent (A2A) architecture for orchestrating multiple specialized agents.

Tokens
215.7K
Snippets
599
Records
780
Agent score
69%

What's inside agent-sdk-go

  1. Overview of agent microservice examples

    main

    The examples/microservices/ directory contains four distinct patterns for implementing distributed agents:

    • Basic Microservice (basic_microservice/): Demonstrates creating a local agent and wrapping it as a gRPC microservice on a specific port.
    • Remote Agent Client (remote_client/): Shows how to connect to a remote agent service via URL and use it like a local agent, including handling connection errors and retries.
    • Mixed Local and Remote (mixed_agents/): Illustrates building a distributed system by using both local and remote agents together as subagents.
    • Microservice Manager (service_manager/): Demonstrates programmatic management of multiple microservices, including starting/stopping services and monitoring health.
  2. Overview of Agent Go SDK

    main

    The Agent Go SDK is a Go framework designed for building production-ready AI agents. It provides a flexible and extensible architecture that integrates several core capabilities:

    • Multi-Model Intelligence: Support for OpenAI, Anthropic, and Google Vertex AI (Gemini).
    • Modular Tool Ecosystem: Plug-and-play tools for web search, data retrieval, and custom operations.
    • Advanced Memory Management: Persistent conversation tracking using buffer or vector-based retrieval.
    • MCP Integration: Support for Model Context Protocol (MCP) servers via HTTP and stdio.
    • Token Usage Tracking: Built-in counting for cost monitoring and analytics.
    • Enterprise Features: Built-in guardrails, complete observability (tracing/logging), and multi-tenancy support.
    • Structured Task Framework: Ability to plan, approve, and execute multi-step operations using declarative YAML configurations.
  3. Understand the Task package organization

    main

    The task package is organized into three primary files to separate data structures, core services, and adapter logic:

    • models.go: Contains all data structures used throughout the task package.
    • service.go: Defines the core Service interface and provides the InMemoryTaskService and AgentTaskService implementations.
    • adapter.go: Implements the TaskAdapter interface and the AdapterService used for working with agent-specific models, including the default implementation.
  4. What is Model Context Protocol (MCP)?

    main
    Model Context Protocol (MCP) is an open standard used by agent-sdk-go to connect AI agents to external tools and data sources. It provides a standardized way to access APIs, execute commands, retrieve context, and maintain secure connections with built-in authentication and permission controls.
  5. What is the A2A (Agent-to-Agent) Protocol?

    main

    A2A is an open protocol that enables AI agents to discover, communicate, and collaborate across different frameworks (e.g., Google ADK, LangChain, CrewAI).

    Key features include:

    • Agent discovery: via /.well-known/agent-card.json.
    • Message exchange: Synchronous and streaming via JSON-RPC.
    • Task lifecycle: Management of working, completed, failed, and canceled states.
    • Multi-turn conversations: Managed via context IDs.

    The pkg/a2a package in agent-sdk-go provides both server (to expose your agents) and client (to call remote agents) implementations.

  6. Overview of MCP Tool Output Schemas

    main

    The MCP Tool Output Schemas feature provides JSON Schema (Draft 7) validation and type safety for Model Context Protocol (MCP) tool responses. It ensures that tool outputs conform to expected structures, which improves error handling and integration reliability when an Agent interacts with an MCP Server via a ToolManager.

    Architecture Flow

    1. Agent: Calls tools and validates types.
    2. ToolManager: Handles validation and manages schemas.
    3. MCP Server: Provides tools and responses.
    4. Validator: The underlying engine performing JSON schema validation, type checking, and rule enforcement.
  7. What is the DataStore component?

    main

    The DataStore component provides a unified interface for storing and retrieving structured data with built-in multi-tenancy support. It allows you to perform CRUD operations, querying, and transactional updates across different database backends using a consistent API.

    Key features include:

    • Unified Interface: The same API works across different database implementations.
    • Multi-Tenancy: Built-in organization-level data isolation via org_id.
    • CRUD Operations: Create, Read, Update, and Delete with automatic ID generation.
    • Query Support: Filtering, limiting, offsetting, and ordering.
    • Transactions: Atomic operations with automatic rollback support.
    • Automatic Timestamps: Managed created_at and updated_at fields.
  8. Configure structured output via struct tags

    main

    When defining Go structs for structured output, you can use specific struct tags to influence how the LLM interprets and populates the data:

    • json:"fieldname": Standard JSON key mapping.
    • description:"...": Provides a natural language description of the field. The SDK uses this to generate the JSON schema, which guides the LLM on what information to place in that field.
    • omitempty: Used within the JSON tag (e.g., json:"field_name,omitempty") to mark fields as optional. This tells the LLM that the field may be omitted from the response if the information is unavailable.
    type Person struct {
        Name        string `json:"name" description:"The person's full name"`
        BirthDate   string `json:"birth_date,omitempty" description:"Date of birth"`
    }
  9. Isolate memory using Multi-tenancy and Conversation IDs

    main

    The SDK supports isolating memory for different users (organizations) and different chat sessions (conversations) using context values.

    Multi-tenancy

    Use multitenancy.WithOrgID(ctx, "org-id") to ensure messages are isolated by organization. This is critical when using shared memory implementations like Redis.

    Conversation Isolation

    Use context.WithValue(ctx, memory.ConversationIDKey, "conv-id") to manage multiple distinct conversations within the same organization or user context.

    import (
        "context"
        "github.com/Ingenimax/agent-sdk-go/pkg/memory"
        "github.com/Ingenimax/agent-sdk-go/pkg/multitenancy"
    )
    
    // Isolate by Organization
    ctx := multitenancy.WithOrgID(context.Background(), "org-123")
    
    // Isolate by Conversation
    ctx = context.WithValue(ctx, memory.ConversationIDKey, "conversation-456")
    
    // Messages added with this ctx will be isolated to org-123 and conversation-456
    err := mem.AddMessage(ctx, interfaces.Message{Role: "user", Content: "Hi"})
  10. Design Resource URIs for MCP

    main

    When accessing resources via the MCP (Model Context Protocol) manager, use structured URIs with specific schemes to ensure clarity and compatibility.

    Recommended Patterns:

    • file:///path/to/resource for file system access.
    • db://database/table?query=param for database queries.
    • api://endpoint/path for API endpoints.
    • stream://topic/name for real-time data streams.

    Avoid:

    • Generic identifiers like resource://unclear-identifier.
    • URIs without schemes like data.
    // Good URI patterns
    "file:///documents/report.pdf"           // File system
    "db://inventory/products?category=tech"  // Database query
    "api://slack/channels/general/messages"  // API endpoint
    "stream://metrics/cpu-usage"             // Real-time data
  11. How Lazy MCP Configuration works with Google CSE

    main

    The example utilizes a Lazy MCP Configuration approach. Instead of starting the MCP server immediately, the server is only initialized when the agent makes its first tool call.

    • The MCP server is executed via the command uvx mcp-google-cse as a stdio process.
    • The required environment variables (API_KEY and ENGINE_ID) are passed directly to the MCP server process.
    • Once initialized, the agent gains access to the google_search tool.
  12. How the Task Adapter Pattern works

    main

    The Task Adapter Pattern allows you to use your own agent-specific models (e.g., custom Task or CreateRequest structs) while still using the SDK's task management logic.

    To use this pattern, you must implement the TaskAdapter interface, which provides conversion methods between your custom models and the SDK's internal task models. This separates your domain models from the SDK's implementation details.

    Implementation Steps

    1. Define your custom models (e.g., MyTask, MyCreateRequest).
    2. Implement the TaskAdapter interface with methods like ConvertCreateRequest, ConvertTask, etc.
    3. Wrap the SDK's Service and your TaskAdapter in an AgentTaskService.
    // Implement conversion methods for your custom adapter
    func (a *MyTaskAdapter) ConvertCreateRequest(req MyCreateRequest) task.CreateTaskRequest {
        return task.CreateTaskRequest{
            Description: req.Name,
            UserID:      req.UserID,
            Metadata:    make(map[string]interface{}),
        }
    }
    
    func (a *MyTaskAdapter) ConvertTask(sdkTask *task.Task) MyTask {
        if sdkTask == nil {
            return MyTask{}
        }
        return MyTask{
            ID:          sdkTask.ID,
            Name:        sdkTask.Description,
            Status:      string(sdkTask.Status),
            CreatedAt:   sdkTask.CreatedAt,
            CompletedAt: sdkTask.CompletedAt,
        }
    }