Skip to main content
Software Engineering

Workshop 04 - Afternoon Session: Agent Orchestration & Safety

10 Modules
Chapter 8: Resources for Agent Orchestration & Safety80%

Resources for Agent Orchestration & Safety

Official Documentation

Anthropic

Model Context Protocol (MCP)

Orchestration Frameworks

Orchestration Patterns

Framework Comparison

FrameworkPatternBest ForComplexity
Claude Code subagentsDelegationCoding tasks, file operationsLow
Custom (Anthropic SDK)Any patternFull control, production systemsMedium
LangGraphState machinesComplex workflows with branchingHigh
CrewAIRole-based teamsContent creation, researchMedium
AutoGenConversationsMulti-agent dialogueMedium

Pattern Reference

# Quick reference for each pattern

# 1. Subagent Delegation
parent_result = synthesise([
    subagent_1.execute(task_a),
    subagent_2.execute(task_b),
])

# 2. Pipeline
result = stage_3(stage_2(stage_1(input)))

# 3. Fan-out / Fan-in
parallel_results = parallel_execute([search_a, search_b, search_c])
result = synthesise(parallel_results)

# 4. LangGraph State Machine
graph.add_edge("plan", "execute")
graph.add_conditional_edges("review", decide, {"revise": "execute", "done": END})

Safety and Cost Management

Safety Checklist

Use this checklist for every production agent system:

  • Token budget controller with per-task limits
  • Iteration limiter (max loops per agent)
  • Timeout controls (max wall-clock time)
  • Sandboxed code execution (E2B, Docker, or restricted Python)
  • Human-in-the-loop approval for destructive actions
  • Audit logging (every tool call, every LLM call)
  • Input validation on all tool parameters
  • Network restrictions (allowlist for outbound connections)
  • Error recovery with retries and fallbacks
  • Cost alerting when approaching budget thresholds

Cost Estimation

Model selection has the biggest impact on cost. Check the Anthropic pricing page for current rates. General guidance:

ModelUse ForRelative Cost
Haiku 4.5Classification, routing, formatting, simple extractionLowest
Sonnet 4.6General work, coding, analysis, synthesisMedium
Opus 4.8Complex reasoning, architecture, critical decisionsHighest

Cost reduction strategies:

  1. Route simple tasks to Haiku (saves significantly per call)
  2. Use prompt caching for repeated system prompts
  3. Trim conversation context aggressively
  4. Batch multiple classifications into one call
  5. Set hard token budgets and stop early

Observability Tools

ToolPurposeLink
LangSmithAgent tracing, debugging, evaluationhttps://docs.smith.langchain.com/
HeliconeLLM observability, cost tracking, cachinghttps://www.helicone.ai/
BraintrustEvaluation and monitoringhttps://www.braintrust.dev/
Weights & BiasesExperiment trackinghttps://wandb.ai/

Code Execution Sandboxes

ToolTypeLink
E2BCloud sandboxeshttps://e2b.dev/
ModalServerless computehttps://modal.com/
DockerLocal containersStandard Docker
RestrictedPythonIn-process sandboxhttps://github.com/zopefoundation/RestrictedPython

Research Papers

Multi-Agent Systems

  1. ReAct: Synergizing Reasoning and Acting (2023)

  2. Generative Agents: Interactive Simulacra of Human Behavior (2023)

  3. Model Context Protocol Specification (2024-2025)

Safety and Alignment

  1. Constitutional AI (2023)

  2. Agent Safety in Production Systems (2025)

    • Focus: Guardrails, cost control, and audit patterns for deployed agents

Development Setup

Required Packages

# Core
pip install anthropic tenacity python-dotenv

# For LangGraph exercises
pip install langgraph langchain langchain-anthropic

# For testing
pip install pytest

Project Template

my_agent_system/
    orchestrator.py      # Main orchestration
    safety.py            # Budget, limits, audit
    router.py            # Model routing
    agents.py            # Subagent implementations
    config.py            # Configuration
    main.py              # Entry point
    tests/
        test_safety.py
        test_router.py
        test_orchestrator.py
    logs/                # Audit logs (gitignored)
    requirements.txt
    .env                 # API keys (gitignored)
    CLAUDE.md            # Agent configuration

Community

Navigation