Overview
Concrete tool for driving the Eino ADK multi-agent event loop provided by the internal/multiagent package.
Description
runEinoADKAgentLoop is the shared control loop for Deep, Plan-Execute, and Supervisor orchestration modes. It takes an einoADKRunLoopArgs (orchestrator agent, conversation ID, progress callback, middleware config, token budgets) and base messages, then runs the Eino ADK event iterator with context hookup. For each event it dispatches to stream/materialize handlers, normalizes streaming deltas, reconciles tool pairs, prunes orphan tool results, and classifies errors (stream cancel, turn-loop preempt, iteration limit, panic) into restart-or-return decisions. It supports retry with exponential backoff on 429/5xx and context-overflow compression.
Usage
- First engagement (step 5): the single-agent and multi-agent runners both call this loop.
- Multi-agent sub-agent execution: each sub-agent turn runs through this loop with its own agent instance.
- HITL continuation: after an approved/rejected tool call, the loop resumes from the tool result.
Code Reference
Source Location
- Repository: CyberStrikeAI
- File: internal/multiagent/eino_adk_run_loop.go
- Lines: einoADKRunLoopArgs L109-155, runEinoADKAgentLoop L157-333
Signature
type einoADKRunLoopArgs struct {
OrchMode, OrchestratorName, ConversationID string
Progress func(eventType, message string, data interface{})
Logger *zap.Logger
DA adk.Agent
MaxTotalTokens, ToolMaxBytes int
ModelName string
MiddlewareConfig *config.MultiAgentEinoMiddlewareConfig
MCPExecutionBinder *MCPExecutionBinder
FilesystemMonitorRecord einomcp.ExecutionRecorder
ToolInvokeNotify *einomcp.ToolInvokeNotifyHolder
EmptyResponseMessage string
// ... retry, callbacks, trace holders ...
}
func runEinoADKAgentLoop(ctx context.Context, args *einoADKRunLoopArgs,
baseMsgs []adk.Message) (*RunResult, error)
type RunResult struct {
Response, LastAgentTraceInput, LastAgentTraceOutput string
MCPExecutionIDs []string
Finalized bool
Status, CompletionReason string
}
Import
// internal package — invoked by RunDeepAgent / RunEinoSingleChatModelAgent
I/O Contract
Inputs
| Name |
Type |
Required |
Description
|
| ctx |
context.Context |
Yes |
Cancellable context for interrupt/shutdown
|
| args |
*einoADKRunLoopArgs |
Yes |
Agent, conversation, progress, budgets, middleware
|
| baseMsgs |
[]adk.Message |
Yes |
Initial message history
|
Outputs
| Name |
Type |
Description
|
| returns |
*RunResult, error |
Final response + traces + MCP execution IDs
|
Usage Examples
Run a Deep Orchestrator
result, err := runEinoADKAgentLoop(ctx, &einoADKRunLoopArgs{
OrchMode: "deep",
OrchestratorName: "orchestrator",
ConversationID: convID,
DA: deepAgent,
Progress: progressCallback,
Logger: zapLogger,
MaxTotalTokens: 100000,
ToolMaxBytes: 12000,
ModelName: "gpt-4o",
}, baseMsgs)
Related Pages
Implements Principle
Uses Heuristic
Requires Environment