Eino Examples
repository·main·Indexed 20 days ago
https://github.com/cloudwego/eino-examplesA 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.
What's inside eino-examples
- This project provides a simplified implementation of a 'manus' agent built using the Eino framework. It is inspired by the OpenManus project. The agent's architecture is designed around the Eino framework's capabilities to orchestrate complex agentic workflows.
What is Eino?
mainEino 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, andPromptTemplate. - 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.
- Atomic Components: Basic building blocks like
Wrap Eino compositions as agent tools using GraphTool
mainThe
graphtoolpackage allows you to wrap Eino's composition types—compose.Graph,compose.Chain, andcompose.Workflow—as agent tools. This enables complex multi-step pipelines to be exposed as single tools that aChatModelAgentcan invoke.Supported Tool Types
Tool Type Interface Use Case InvokableGraphTooltool.InvokableToolStandard request-response tools StreamableGraphTooltool.StreamableToolTools that stream output incrementally Installation
import "github.com/cloudwego/eino-examples/adk/common/tool/graphtool"Explore Eino ADK Agent Examples
mainThe
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
helloworldchat agent andintroexamples coveringChatModelAgentwith interrupts, custom agent implementations, and workflow-based agents (Loop,Parallel,Sequential). - Multi-Agent Systems: Implementations of
supervisorpatterns,layered-supervisor(nested supervisors),plan-execute-replanloops, anddeepagents. - Agentic Capabilities: Advanced usage of
AgenticModelwith typed agents, server-side search, local tools, filesystem middleware, andAgenticMessageoutput.
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
sessionand managing long-running agent state with conversation summarization. - Middleware & Tools: Using
skillmiddleware to load agent skills from the filesystem, anddynamictool/toolsearchfor 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).
- Basic Agents: Simple
What is a Ralph Loop and how does it work?
mainA 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:
- Repeated Prompting: A single task prompt is fed to an AI agent repeatedly.
- 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). - Completion Signal: The agent signals it is finished by outputting a specific string called a
CompletionPromise(default is<COMPLETE/>). - Verification Gate: A caller-defined
VerifyCompletionfunction 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. - Safety Bounds: A
MaxTurnslimit 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 │ │ │ └────────────────────────────────────────────────┘ │ └──────────────────────────────────────────────────────┘What is A2UI and how does it work
mainA2UI (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
AgentEventstreams into a tree of UI components that the browser can render incrementally.What is a Graph Tool and when to use it
mainA Graph Tool is a Tool-based encapsulation of an Eino
compose.Graph,compose.Chain, orcompose.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
composepackage to organize complex, deterministic business processes. - Parallelism & Branching: Supports parallel execution, branching, and sub-graphs via the
composeengine. - 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.
- Orchestration: Uses the
What is TurnLoop and when to use it
mainUnlike the
adk.Runnerwhich follows a single-turn model (one call, one execution, one end),adk.TurnLoopis 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:
Capability Runner (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 GenInputcallbackWhat is Eino and its core design principles
mainEino 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
Componentinterface to create replaceable and composable units of capability (e.g., ChatModel, Tool, Retriever, Loader). - Orchestration Framework: Provides abstractions like
Agent,Graph, andChainto support complex multi-step AI workflows. - Runtime Support: Includes built-in capabilities for streaming output, interruption/resumption, state management, and observability via Callbacks.
Configure the `coder` agent prompt
mainThe
coderagent is a specialized professional software engineer agent designed to be managed by asupervisoragent. 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
yfinancelibrary for all financial market data tasks.
Operational Workflow
- Analyze: Review task objectives and constraints.
- Plan: Determine if Python is required and outline steps.
- Implement: Write Python code. Crucial: To inspect values or debug, you MUST use
print(...)to display outputs. - Test: Verify implementation and edge case handling.
- Document: Explain the reasoning and assumptions.
- Present: Display final results.
Environment & Constraints
- Pre-installed Packages:
pandas,numpy, andyfinanceare available in the execution environment. - Financial Data Patterns:
- Use
yf.download()for historical data. - Use
Tickerobjects for company information.
- Use
- Localization: The agent is instructed to output in the locale specified by the
{{ locale }}variable.
Understand the Review and Edit Human-in-the-loop pattern
mainThe 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
- Tool Call Identification: The agent identifies a tool and prepares the necessary arguments.
- Review Interruption: An
InvokableReviewEditToolwrapper intercepts the call and presents the arguments to the user. - Human Decision: The user can choose one of three paths:
- Edit Parameters: Provide corrected JSON arguments.
- Approve as-is: Input
no need to editto proceed with original parameters. - Reject: Input
N(or '拒绝') to cancel the tool call, optionally providing a reason.
- 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.
How Deep Agents and Follow-Up patterns work
mainThe 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
- User Request: User provides a query (e.g., "Analyze market trends").
- Ambiguity Detection: The Deep Agent identifies missing parameters.
- Interruption: The agent uses
FollowUpToolto pause and present questions to the user. - User Response: The user provides answers to the questions.
- Resumption: The system resumes, carrying the user's answers into the next phase.
- Delegation: The Deep Agent delegates tasks to
ResearchAgentandAnalysisAgentbased on the clarified requirements. - 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[最终响应];