gearsAdvanced Patterns

Advanced agent patterns: pipeline integration, dynamic tools, introspection, event interception, and best practices.

Pipeline Integration

Agents implement IAiRunnable, so they plug directly into composable pipelines:

agent = aiAgent(
    name        : "Summarizer",
    instructions: "Create concise summaries of the provided content"
)

pipeline = aiMessage()
    .user( "Task: ${task}" )
    .to( agent )
    .transform( r => r.toUpper() )

result = pipeline.run( { task: "Summarize AI trends in 2025" } )

Chaining Agents

Multiple agents can be chained in sequence, each processing the output of the previous:

researchAgent = aiAgent( name: "Researcher",  instructions: "Research topics thoroughly" )
summaryAgent  = aiAgent( name: "Summarizer",  instructions: "Create concise summaries" )
editorAgent   = aiAgent( name: "Editor",      instructions: "Polish and format content" )

pipeline = aiMessage()
    .user( "Research: ${topic}" )
    .to( researchAgent )
    .transform( r => "Summarize this: ${r}" )
    .to( summaryAgent )
    .transform( r => "Edit and polish: ${r}" )
    .to( editorAgent )

result = pipeline.run( { topic: "Quantum Computing" } )

Dynamic Tool Assignment

Assign different tools to an agent based on runtime context:

Agent Introspection

Inspect a running agent's full configuration at any time via getConfig():

Conditional Agent Execution

Create different agents based on runtime conditions:

Event Interception

Agents fire events at key lifecycle points. Use BoxRegisterInterceptor() to observe them:

See Events Reference for the full list of agent events.

5 Best Practices

1. Provide Clear, Specific Instructions

2. Give Agents Only the Tools They Need

3. Manage Memory Lifecycle

4. Tune Parameters per Task Type

5. Handle Errors Gracefully

Last updated