Eino Examples

repository·main·Indexed 20 days ago

https://github.com/cloudwego/eino-examples

A demonstration repository for the Eino framework featuring practical implementations of Agentic patterns, orchestration workflows, and core components. Includes examples of the Ralph Loop autonomous agent pattern, Agentic Research Assistants using AgenticMessage and ContentBlocks, document summarization tools via compose.Chain, and streaming research tools using StreamableGraphTool. Provides guidance on implementing retry strategies for max output tokens and building parallel workflows with compose.Workflow.

Tokens
123.2K
Snippets
295
Records
407
Agent score
71%

What's inside eino-examples

  1. What is Eino?

    main

    Eino is a Go-based development framework for integrating AI capabilities into applications. It is designed to be idiomatic to Golang and provides a structured way to build AI applications by offering atomic components, integrated components, orchestration (Graph/Chain), and aspect-oriented extensions (AOP).

    Key features include:

    • Atomic Components: Basic building blocks like ChatModel, ToolNode, and PromptTemplate.
    • Orchestration: Ability to compose components into complex workflows (e.g., a React Agent).
    • Extensibility: Support for custom business logic and cross-cutting concerns like observability, rate limiting, and evaluation.
  2. Wrap Eino compositions as agent tools using GraphTool

    main

    The graphtool package allows you to wrap Eino's composition types—compose.Graph, compose.Chain, and compose.Workflow—as agent tools. This enables complex multi-step pipelines to be exposed as single tools that a ChatModelAgent can invoke.

    Supported Tool Types

    Tool TypeInterfaceUse Case
    InvokableGraphTooltool.InvokableToolStandard request-response tools
    StreamableGraphTooltool.StreamableToolTools that stream output incrementally

    Installation

    import "github.com/cloudwego/eino-examples/adk/common/tool/graphtool"
  3. Explore Eino ADK Agent Examples

    main

    The adk/ directory contains a comprehensive collection of examples for the Eino Agent Development Kit (ADK), categorized by architectural patterns and capabilities:

    Core Agent Patterns

    • Basic Agents: Simple helloworld chat agent and intro examples covering ChatModelAgent with interrupts, custom agent implementations, and workflow-based agents (Loop, Parallel, Sequential).
    • Multi-Agent Systems: Implementations of supervisor patterns, layered-supervisor (nested supervisors), plan-execute-replan loops, and deep agents.
    • Agentic Capabilities: Advanced usage of AgenticModel with typed agents, server-side search, local tools, filesystem middleware, and AgenticMessage output.

    Human-in-the-Loop (HITL) Patterns

    Examples demonstrating how to integrate human intervention into agent workflows:

    • Approval & Review: Sensitive operation approval (1_approval), reviewing and editing tool-call arguments (2_review-and-edit), and supervisor patterns with approval (5_supervisor).
    • Iterative Loops: Writer/reviewer feedback loops (3_feedback-loop) and plan-execute-replan with review/edit (6_plan-execute-replan).
    • Information Gathering: Asking follow-up questions when information is missing (4_follow-up).

    Advanced Features & Middleware

    • State & Session Management: Passing data across agents using session and managing long-running agent state with conversation summarization.
    • Middleware & Tools: Using skill middleware to load agent skills from the filesystem, and dynamictool/toolsearch for retrieving relevant tools from large sets.
    • Operational Patterns: Graceful exit/cancellation of nested agents from terminal signals and retrying when model output is truncated by max_output_tokens.
    • Service Integration: Exposing the ADK Runner as an HTTP SSE service (http-sse-service).
  4. What is a Ralph Loop and how does it work?

    main

    A Ralph Loop is an autonomous agent iteration pattern designed for complex, multi-step tasks. Instead of a single long-running session, the pattern follows these steps:

    1. Repeated Prompting: A single task prompt is fed to an AI agent repeatedly.
    2. Fresh Context, Persistent State: Each turn provides the agent with a fresh context window, but the agent discovers its prior work via a persistent filesystem (e.g., an InMemoryBackend).
    3. Completion Signal: The agent signals it is finished by outputting a specific string called a CompletionPromise (default is <COMPLETE/>).
    4. Verification Gate: A caller-defined VerifyCompletion function inspects the state to decide if the agent's claim of completion is valid. If the function returns an error, the loop rejects the completion and triggers another turn.
    5. Safety Bounds: A MaxTurns limit prevents infinite loops.

    This pattern is ideal for tasks like debugging, where an agent must iteratively find, fix, and verify issues until no more markers (like // BUG:) remain.

    ┌──────────────────────────────────────────────────────┐
    │                   RalphLoop.Run()                     │
    │                                                      │
    │  for turn := 1; turn <= MaxTurns; turn++ {           │
    │                                                      │
    │    ┌──────────────────────────────────────────────┐  │
    │    │  Runner.Run(prompt)                          │  │
    │    │    → Agent executes one turn using fs tools  │  │
    │    │    → Collects text output                    │  │
    │    └──────────────────────┬───────────────────────┘  │
    │                           │                          │
    │    CompletionPromise in output?                       │
    │      YES → VerifyCompletion()                        │
    │              ├─ error → REJECT, continue loop        │
    │              └─ nil   → ACCEPT, return result        │
    │      NO  → continue loop                             │
    │                                                      │
    │  }                                                    │
    │  → max turns reached, return result                   │
    │                                                      │
    │  ┌────────────────────────────────────────────────┐  │
    │  │          InMemoryBackend (shared)              │  │
    │  │    Files persist across all turns              │  │
    │  │    Pre-seeded with buggy starter project       │  │
    │  └────────────────────────────────────────────────┘  │
    └──────────────────────────────────────────────────────┘
  5. What is A2UI and how does it work

    main

    A2UI (Agent-to-UI) is a business-layer protocol and rendering scheme designed to map an Agent's output to streaming UI components. Unlike pure text output, A2UI allows for structured data (tables, cards), real-time updates (progress bars), and interactive elements (buttons, forms).

    Key Mental Model:

    • Declarative: The Agent declares what to show; the UI handles how to render it.
    • Streaming: It supports incremental rendering via Server-Sent Events (SSE), allowing components to update as the Agent generates content.
    • Protocol vs. Framework: A2UI is not part of the Eino framework itself but is a rendering layer that can be integrated with Eino-based Agents.

    A2UI v0.8 Subset (Implementation in this example): This implementation focuses on converting AgentEvent streams into a tree of UI components that the browser can render incrementally.

  6. What is a Graph Tool and when to use it

    main

    A Graph Tool is a Tool-based encapsulation of an Eino compose.Graph, compose.Chain, or compose.Workflow. While a simple Tool performs a single task (e.g., reading a file), a Graph Tool implements a multi-step pipeline (e.g., Read → Chunk → Score → Filter → Generate Answer).

    Key benefits of Graph Tools:

    • Orchestration: Uses the compose package to organize complex, deterministic business processes.
    • Parallelism & Branching: Supports parallel execution, branching, and sub-graphs via the compose engine.
    • State Management: Handles data passing between nodes and supports state persistence via checkpointing.
    • Interrupt/Resume: Supports both internal workflow interruptions and tool-level interrupt wrapping.
  7. What is TurnLoop and when to use it

    main

    Unlike the adk.Runner which follows a single-turn model (one call, one execution, one end), adk.TurnLoop is a persistent multi-turn execution loop. It is designed for long-running user sessions where the Agent needs to support real-time interactions like Preemption (interrupting a current answer to ask something else) and Abortion (stopping the Agent entirely).

    Key Differences:

    CapabilityRunner (Single-turn)TurnLoop (Multi-turn)
    Streaming Output
    Approval/Interrupt
    Persistent Lifecycle❌ Independent Run() calls✅ Continuous loop via Push()
    Preempt current answer✅ via Push(item, WithPreempt(...))
    Abort Agent✅ via loop.Stop(...)
    Input Construction❌ Manual assembly✅ via GenInput callback
  8. What is Eino and its core design principles

    main

    Eino is an AI Application Development Kit (ADK) implemented in Go. It is designed to help developers build scalable and maintainable AI applications through several key abstractions:

    • Model Abstraction: Unifies interfaces for different LLM providers (OpenAI, Ark, Claude, etc.), allowing you to switch models without changing business logic.
    • Component Interface: Uses a Component interface to create replaceable and composable units of capability (e.g., ChatModel, Tool, Retriever, Loader).
    • Orchestration Framework: Provides abstractions like Agent, Graph, and Chain to support complex multi-step AI workflows.
    • Runtime Support: Includes built-in capabilities for streaming output, interruption/resumption, state management, and observability via Callbacks.
  9. Configure the `coder` agent prompt

    main

    The coder agent is a specialized professional software engineer agent designed to be managed by a supervisor agent. It is optimized for Python scripting, data analysis, and financial market data retrieval.

    Agent Persona and Capabilities

    • Role: Professional software engineer proficient in Python.
    • Primary Task: Analyze requirements, implement solutions in Python, and document methodology.
    • Math & Data: Must use Python for all mathematical operations and data analysis.
    • Financial Data: Must use the yfinance library for all financial market data tasks.

    Operational Workflow

    1. Analyze: Review task objectives and constraints.
    2. Plan: Determine if Python is required and outline steps.
    3. Implement: Write Python code. Crucial: To inspect values or debug, you MUST use print(...) to display outputs.
    4. Test: Verify implementation and edge case handling.
    5. Document: Explain the reasoning and assumptions.
    6. Present: Display final results.

    Environment & Constraints

    • Pre-installed Packages: pandas, numpy, and yfinance are available in the execution environment.
    • Financial Data Patterns:
      • Use yf.download() for historical data.
      • Use Ticker objects for company information.
    • Localization: The agent is instructed to output in the locale specified by the {{ locale }} variable.
  10. Understand the Review and Edit Human-in-the-loop pattern

    main

    The Review and Edit pattern is a complex human-in-the-loop (HITL) mode designed for high-stakes agentic workflows. It uses a tool wrapper architecture to intercept tool calls before they are executed, allowing a human user to perform fine-grained control over the agent's actions.

    How it works

    1. Tool Call Identification: The agent identifies a tool and prepares the necessary arguments.
    2. Review Interruption: An InvokableReviewEditTool wrapper intercepts the call and presents the arguments to the user.
    3. Human Decision: The user can choose one of three paths:
      • Edit Parameters: Provide corrected JSON arguments.
      • Approve as-is: Input no need to edit to proceed with original parameters.
      • Reject: Input N (or '拒绝') to cancel the tool call, optionally providing a reason.
    4. Resumption: The system resumes execution using the user's decision (the edited parameters, the original parameters, or a cancellation).

    Key Benefits

    • Parameter-level control: Fix incorrect or incomplete data before it hits a real system.
    • Safety: Prevent harmful or unintended tool executions.
    • Transparency: Full visibility into what the agent intends to do.
  11. How Deep Agents and Follow-Up patterns work

    main

    The Deep Agents pattern combines multi-agent orchestration with a Follow-Up (Human-in-the-loop) mechanism. This pattern is used to build deep reasoning systems that proactively seek clarification when user requirements are ambiguous.

    Core Components

    • Deep Agent (Orchestrator): A central agent that coordinates specialized sub-agents and manages the workflow.
    • Specialized Sub-Agents:
      • ResearchAgent: Handles searching for market, technical, or financial information.
      • AnalysisAgent: Performs trend, comparison, and statistical analysis.
    • FollowUpTool: A tool used by the Deep Agent to trigger an interruption. When the agent identifies ambiguity (e.g., missing timeframes, industries, or risk tolerances), it calls this tool to pause execution and ask the user for specific information.

    Workflow Lifecycle

    1. User Request: User provides a query (e.g., "Analyze market trends").
    2. Ambiguity Detection: The Deep Agent identifies missing parameters.
    3. Interruption: The agent uses FollowUpTool to pause and present questions to the user.
    4. User Response: The user provides answers to the questions.
    5. Resumption: The system resumes, carrying the user's answers into the next phase.
    6. Delegation: The Deep Agent delegates tasks to ResearchAgent and AnalysisAgent based on the clarified requirements.
    7. Final Output: A comprehensive report is generated based on the specific user preferences.
    graph TD
        A[用户请求] --> B{深度智能体};
        B --> C[识别模糊性];
        C --> D[FollowUpTool];
        D --> E[中断:提问];
        E --> F{用户回答};
        F --> G[恢复并携带答案];
        G --> H[委托给 ResearchAgent];
        H --> I[搜索市场数据];
        I --> J[返回研究结果];
        J --> B;
        B --> K[委托给 AnalysisAgent];
        K --> L[分析数据];
        L --> M[返回分析结果];
        M --> B;
        B --> N[生成最终报告];
        N --> O[最终响应];