Eino Examples Adapter

April 19, 2026 ยท View on GitHub

This document describes the eino_examples integration in CoRag, which provides adapters for cloudwego/eino-examples patterns.

Overview

The internal/agent/runtime/executor/eino_examples package provides adapters for various eino agent and workflow patterns:

PatternAdapterDescription
ReAct AgentReactAgentAdapterReasoning + Action pattern with tool usage
DEER-Go AgentDEERAgentAdapterDEER-Go agent pattern
Manus AgentManusAgentAdapterManus agent pattern
ADKADKAdapterGoogle ADK agent pattern
ChainChainAdapterSequential pipeline composition
GraphGraphAdapterDAG-based composition with edges
WorkflowWorkflowAdapterFlexible workflow composition

Installation

The eino_examples package is included in the CoRag module. Ensure you have the dependencies:

go mod tidy

Quick Start

1. Create a ChatModel

import (
    eino_examples "github.com/Colin4k1024/Aetheris/v2/internal/agent/runtime/executor/eino_examples"
    "github.com/Colin4k1024/Aetheris/v2/internal/model/llm"
)

// Using Ollama (local LLM)
client, _ := llm.NewOllamaClient("llama3", "http://localhost:11434")
model := eino_examples.NewOllamaChatModel(client)

// Using OpenAI
client, _ := llm.NewClient("openai", "gpt-4", apiKey, "")
model := eino_examples.NewOpenAIChatModel(client)

// Using Claude
client, _ := llm.NewClient("claude", "claude-3-haiku-20240307", apiKey, "")
model := eino_examples.NewClaudeChatModel(client)

2. Create Agent Adapter

// ReAct Agent with tools
adapter := eino_examples.NewReactAgentAdapter(model, tools,
    eino_examples.WithTemperature(0.7),
    eino_examples.WithMaxTokens(2048),
)

// DEER-Go Agent
deerAdapter := eino_examples.NewDEERAgentAdapter(model, tools)

// Manus Agent
manusAdapter := eino_examples.NewManusAgentAdapter(model, tools)

3. Execute

ctx := context.Background()

result, err := adapter.Invoke(ctx, map[string]any{
    "prompt": "Calculate 15 + 27 using the calculator tool",
})
if err != nil {
    log.Fatal(err)
}

fmt.Println(result["response"])

Examples

ReAct Agent with Tools

See examples/eino_agent_with_tools/ for a complete example:

go run ./examples/eino_agent_with_tools/main.go

This example demonstrates:

  • Creating a calculator tool
  • Using ReAct agent with tool calling
  • Integrating with CoRag executor

Chain Composition

chain := eino_examples.NewChainAdapter()

chain.AddNode("step1", func(ctx context.Context, input any) (any, error) {
    return map[string]any{"result": "step1 done"}, nil
})

chain.AddNode("step2", func(ctx context.Context, input any) (any, error) {
    return map[string]any{"result": "step2 done"}, nil
})

result, _ := chain.Invoke(ctx, map[string]any{"input": "test"})

Graph Composition

graph := eino_examples.NewGraphAdapter()

graph.AddNode("input", inputNode)
graph.AddNode("process", processNode)
graph.AddNode("output", outputNode)

graph.AddEdge("input", "process")
graph.AddEdge("process", "output")
graph.SetEntry("input")

result, _ := graph.Invoke(ctx, map[string]any{"data": "test"})

LLM Provider Configuration

Environment Variables

VariableDescriptionDefault
OLLAMA_MODELOllama model namellama3
OLLAMA_BASE_URLOllama API endpointhttp://localhost:11434
OPENAI_API_KEYOpenAI API key-
OPENAI_MODELOpenAI model namegpt-3.5-turbo
ANTHROPIC_API_KEYAnthropic Claude API key-

Using Docker Compose

In docker-compose.v2.yml, configure the LLM provider:

environment:
  - MODEL_DEFAULTS_LLM=openai.gpt_35_turbo
  - MODEL_LLM_PROVIDERS_OPENAI_BASE_URL=http://host.docker.internal:11434/v1
  - MODEL_LLM_PROVIDERS_OPENAI_API_KEY=ollama
  - MODEL_LLM_PROVIDERS_OPENAI_MODELS_GPT_35_TURBO_NAME=llama3

Token Metrics

The eino_examples adapters automatically track token usage:

// Tokens are recorded via Prometheus metrics
metrics.LLMTokensTotal.WithLabelValues("input").Add(float64(inputTokens))
metrics.LLMTokensTotal.WithLabelValues("output").Add(float64(outputTokens))

View metrics at: http://localhost:9093/metrics (Worker metrics port)

API Reference

ChatModel Interface

type ChatModel interface {
    Generate(ctx context.Context, input []*schema.Message, opts ...Option) (*schema.Message, error)
    Stream(ctx context.Context, input []*schema.Message, opts ...Option) (*schema.StreamReader[*schema.Message], error)
}

EinoExampleAdapter Interface

type EinoExampleAdapter interface {
    Invoke(ctx context.Context, input map[string]any) (map[string]any, error)
    Stream(ctx context.Context, input map[string]any, onChunk func(chunk map[string]any) error) error
    GetState(ctx context.Context) (map[string]any, error)
}

Options

OptionDescription
WithTemperature(t float64)Set LLM temperature (0.0-2.0)
WithMaxTokens(n int)Set max tokens for response