Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Multi-Agent Keywords

This section covers keywords for building multi-agent systems where multiple specialized bots collaborate to handle complex tasks.

Overview

Multi-agent orchestration enables:

  • Task specialization - Each bot focuses on what it does best
  • Collaborative problem-solving - Bots work together on complex tasks
  • Scalable architectures - Add new specialists without modifying existing bots
  • Resilient systems - Failures are isolated and handled gracefully

Keyword Summary

KeywordSyntaxDescription
ADD BOTADD BOT "name" TRIGGER ON "keywords"Add bot to session with triggers
DELEGATE TO BOTresult = DELEGATE "msg" TO BOT "name"Send task to another bot
BROADCAST TO BOTSBROADCAST "message" TO BOTSSend message to all bots
TRANSFER CONVERSATIONTRANSFER CONVERSATION TO "botname"Hand off conversation
BOT REFLECTIONBOT REFLECTION trueEnable agent self-analysis
BOT REFLECTION INSIGHTSinsights = BOT REFLECTION INSIGHTS()Get reflection results

ADD BOT

Adds a bot to the current session with optional triggers, tools, and schedules.

' Add bot with keyword triggers
ADD BOT "billing-bot" TRIGGER ON "billing,invoice,payment"

' Add bot with tool access
ADD BOT "analyst-bot" TOOLS "calculate,forecast,report"

' Add bot with scheduled execution
ADD BOT "monitor-bot" SCHEDULE "0 */1 * * *"

' Add bot with multiple configurations
ADD BOT "support-bot" TRIGGER ON "help,support" TOOLS "ticket,escalate"

Trigger Types

TypeDescriptionExample
TRIGGER ONKeyword-based activationTRIGGER ON "billing,payment"
TOOLSTool-based activationTOOLS "calculate,search"
SCHEDULECron-based activationSCHEDULE "0 9 * * *"

DELEGATE TO BOT

Sends a task to another bot and optionally waits for a response.

' Fire-and-forget delegation
DELEGATE "Process this order" TO BOT "order-processor"

' Get response from delegation
result = DELEGATE "Calculate ROI" TO BOT "finance-bot"
TALK "Result: " + result

' Delegation with timeout
result = DELEGATE "Analyze report" TO BOT "analyst-bot" TIMEOUT 60

Parameters

ParameterTypeDescription
messageStringTask or message to send
botnameStringTarget bot name
TIMEOUTNumberOptional timeout in seconds (default: 30)

BROADCAST TO BOTS

Sends a message to all bots in the current session.

' Notify all bots of an event
BROADCAST "New customer signup: " + customerid TO BOTS

' Emergency signal
BROADCAST "MAINTENANCE_MODE" TO BOTS

' Data update notification
BROADCAST "PRICE_UPDATE:" + JSON(prices) TO BOTS

TRANSFER CONVERSATION

Hands off the entire conversation to another bot. The current bot exits.

' Simple transfer
TALK "Let me connect you with our billing specialist."
TRANSFER CONVERSATION TO "billing-bot"

' Transfer with context
SET CONTEXT "issue" AS "refund request"
SET CONTEXT "amount" AS "$150"
TRANSFER CONVERSATION TO "refunds-bot"

' Conditional transfer
IF issueType = "technical" THEN
    TRANSFER CONVERSATION TO "tech-support-bot"
ELSE
    TRANSFER CONVERSATION TO "general-support-bot"
END IF

BOT REFLECTION

Enables agent self-analysis for continuous improvement.

' Enable reflection
BOT REFLECTION true

' Disable reflection
BOT REFLECTION false

' Monitor specific metric
BOT REFLECTION ON "conversation_quality"
BOT REFLECTION ON "response_accuracy"
BOT REFLECTION ON "user_satisfaction"

Reflection Metrics

MetricDescription
conversation_qualityOverall conversation effectiveness
response_accuracyCorrectness of responses
user_satisfactionEstimated user satisfaction
tone_appropriatenessWhether tone matches context
resolution_rateWhether issues were resolved

BOT REFLECTION INSIGHTS

Retrieves the results of reflection analysis.

' Get insights
insights = BOT REFLECTION INSIGHTS()

' Access properties
PRINT "Quality Score: " + insights.qualityScore
PRINT "Issues: " + insights.issuesCount

' Iterate suggestions
FOR EACH suggestion IN insights.suggestions
    PRINT "Suggestion: " + suggestion
NEXT suggestion

' Use for alerting
IF insights.qualityScore < 0.5 THEN
    SEND MAIL admin, "Low Quality Alert", insights.summary
END IF

Insights Object

PropertyTypeDescription
qualityScoreNumberOverall quality (0-1)
summaryStringText summary
issuesArrayIdentified issues
issuesCountNumberCount of issues
suggestionsArrayImprovement suggestions
criticalIssuesNumberCritical problem count
timestampDateTimeWhen analyzed

Common Patterns

Router Pattern

A central bot routes queries to specialists.

' router-bot/start.bas
HEAR userquery

' Classify the query
category = LLM "Classify into: billing, technical, sales, general. Query: " + userquery

SWITCH category
    CASE "billing"
        result = DELEGATE userquery TO BOT "billing-bot"
    CASE "technical"
        result = DELEGATE userquery TO BOT "tech-bot"
    CASE "sales"
        result = DELEGATE userquery TO BOT "sales-bot"
    CASE ELSE
        result = LLM userquery
END SWITCH

TALK result

Expert Panel Pattern

Multiple bots provide perspectives.

question = "Should we expand into Europe?"

' Get multiple expert opinions
marketView = DELEGATE question TO BOT "market-analyst"
financeView = DELEGATE question TO BOT "finance-expert"
riskView = DELEGATE question TO BOT "risk-assessor"

' Synthesize
synthesis = LLM "Combine these expert views: " + marketView + financeView + riskView
TALK synthesis

Escalation Pattern

Automatic escalation when confidence is low.

' First-line bot
confidence = LLM "Rate confidence (0-100) for: " + userquery

IF confidence < 50 THEN
    TALK "Let me connect you with a specialist."
    SET CONTEXT "escalation_reason" AS "low_confidence"
    TRANSFER CONVERSATION TO "senior-support-bot"
ELSE
    response = LLM userquery
    TALK response
END IF

Configuration

config.csv Options

name,value
a2a-enabled,true
a2a-timeout,30
a2a-max-hops,5
a2a-retry-count,3
reflection-enabled,true
reflection-interval,10
reflection-min-messages,3
OptionDefaultDescription
a2a-enabledtrueEnable agent-to-agent communication
a2a-timeout30Default delegation timeout (seconds)
a2a-max-hops5Maximum delegation chain depth
a2a-retry-count3Retry attempts on failure
reflection-enabledtrueEnable bot reflection
reflection-interval10Messages between reflections

Best Practices

  1. Use descriptive bot names - billing-bot not bot2
  2. Set appropriate timeouts - Long tasks need longer timeouts
  3. Handle failures gracefully - Always have fallback paths
  4. Avoid circular delegation - Bot A → Bot B → Bot A
  5. Keep chains short - Max 3-4 delegation hops
  6. Log delegations - Helps debug multi-agent flows
  7. Review reflection insights - Act on improvement suggestions

See Also