Skip to content

Agent Orchestration

This tutorial covers advanced agent patterns: multi-agent systems, tool calling, streaming execution, and autonomous workflows.

Prerequisites


Multi-agent systems

Agent team architecture

Multi-agent systems in LenserFight use Agent Teams — groups of specialized agents that collaborate on tasks:

Agent Team: "Research Squad"
  ├── Strategist (GPT-4o)      → plans the research approach
  ├── Researcher (Claude)       → gathers and synthesizes data
  ├── Critic (GPT-4o-mini)     → evaluates findings for bias
  └── Summarizer (Llama 3.2)   → produces the final report

Creating an agent team

bash
# Create the team
lf team create --name "Research Squad" --template research-team

# Add agents with roles
lf team add-lenser <team-id> --lenser <strategist-id> --role strategist
lf team add-lenser <team-id> --lenser <researcher-id> --role researcher
lf team add-lenser <team-id> --lenser <critic-id> --role critic
lf team add-lenser <team-id> --lenser <summarizer-id> --role summarizer

Role types

RoleResponsibilityWhen to use
strategistPlans execution, sets prioritiesComplex multi-step tasks
executorCarries out planned actionsStandard task execution
criticEvaluates output qualityQuality assurance
researcherGathers and analyzes informationData-driven tasks
evaluatorScores and ranks resultsComparison and evaluation
moderatorEnforces rules and guidelinesSafety and compliance

Tool calling pipelines

How tool calling works

1. Agent receives prompt
2. Agent decides to call a tool (e.g., web_search)
3. Platform executes the tool
4. Tool result is injected back into context
5. Agent continues with enriched context
6. Steps 2–5 repeat until task is complete

Configuring tool chains

yaml
# Example: Research + Code pipeline
tools:
  - name: web_search
    config:
      max_results: 5
      allowed_domains: ["github.com", "docs.*"]
  - name: code_exec
    config:
      language: python
      timeout_ms: 30000
      sandbox: true
  - name: file_read
    config:
      max_size_kb: 500
      allowed_types: [".md", ".txt", ".json"]

Building a tool-calling workflow

  1. Create a workflow with a single node
  2. Assign an agent with tools enabled
  3. The agent autonomously decides when to use tools:
User: "Research the top 5 JavaScript frameworks and create a comparison table"

Agent thinking:
  → Call web_search("top JavaScript frameworks 2026")
  → Read results
  → Call web_search("React vs Vue vs Svelte comparison")
  → Read results
  → Generate comparison table from gathered data

Streaming workflows

Real-time execution

LenserFight supports streaming token-by-token output from workflows:

FeatureDescription
Token streamingSee output as it generates
Node streamingWatch each node execute in sequence
Progress eventsReceive status updates via SSE/WebSocket

Enabling streaming

In the web app:

  1. Click Run on a workflow
  2. Streaming is enabled by default
  3. Watch tokens appear in real time in the result panel

Via API:

bash
curl -N "https://api.lenserfight.com/v1/workflows/<id>/run?stream=true" \
  -H "Authorization: Bearer $API_KEY" \
  -H "Accept: text/event-stream" \
  -d '{"params": {"topic": "AI safety"}}'

Stream events

EventPayloadTiming
run.started{runId, workflowId}Run begins
node.started{nodeId, lensId}Node execution starts
node.token{nodeId, token}Each generated token
node.completed{nodeId, output, tokens}Node finishes
node.failed{nodeId, error}Node error
run.completed{runId, outputs, cost}Run finishes

MCP integrations

Model Context Protocol

LenserFight supports MCP for standardized tool and context sharing:

  1. Connect an MCP server as a tool source
  2. Tools from the MCP server become available to agents
  3. Context from MCP is injected into prompts automatically

Connecting an MCP server

bash
lf mcp connect \
  --name "My MCP Server" \
  --url "http://localhost:3100" \
  --transport stdio

Autonomous workflows

Self-directed execution

Create workflows where agents decide the next step:

[Planner Agent]
    ↓ (plan)
[Router Node] → decides which path
    ├── Path A: [Research Agent] → [Summarizer]
    ├── Path B: [Code Agent] → [Reviewer]
    └── Path C: [Analysis Agent] → [Reporter]

Guardrails for autonomous agents

GuardrailPurposeConfiguration
Token budgetPrevent runaway costsMax tokens per run
Tool allowlistRestrict capabilitiesAllowed tool names
Iteration limitPrevent infinite loopsMax tool-calling rounds
Approval gatesHuman-in-the-loopPause before sensitive actions
Kill switchEmergency stopPlatform-level circuit breaker

Context engineering

Effective context strategies

StrategyWhen to useExample
Retrieval-augmentedLarge knowledge basesAttach relevant docs before prompting
Chain-of-thoughtComplex reasoning"Think step by step before answering"
Few-shotPattern learningProvide 3–5 examples in the prompt
System prompt layeringMulti-concern instructionsPersonality + task + format instructions

Memory systems

SystemScopePersistence
Conversation memorySingle sessionSession duration
Agent memoryPer agentPermanent
Workspace memoryAll agents in workspacePermanent
Semantic searchIndexed knowledgePermanent
bash
# Create a memory entry
lf memory create --lenser <id> \
  --content "User prefers concise bullet-point format for reports"

# Search memory
lf memory search --lenser <id> --query "formatting preferences"

Best practices

  1. Start with single agents — add complexity only when needed
  2. Define clear roles — each agent should have a focused responsibility
  3. Set budget limits — autonomous agents can burn through credits quickly
  4. Use approval gates — for destructive or expensive actions
  5. Monitor execution logs — review tool-calling patterns for efficiency
  6. Test with small inputs — validate behavior before scaling

Next steps