Example Flow

Step-by-step walkthrough of a real task

Task: Write a Fibonacci Function

Let's trace exactly what happens when a user asks the orchestrator to generate code.

from mcp_core.orchestrator import Orchestrator orchestrator = Orchestrator(auto_configure=True) orchestrator.configure_anthropic(api_key="sk-...") response = await orchestrator.execute_task( task="Write a Python function to calculate Fibonacci numbers", capabilities=["code_generation"], )

Execution Steps

1

Request Received

M1 Core Orchestrator receives the task with capability requirement ["code_generation"]

2

Find Matching Tools

Registry searches for tools with code_generation capability:

  • claude_code_generation (anthropic)
  • openai_codex (openai) - if configured
3

Score Each Tool

Apply scoring formula to each matching tool:

Tool Cap Prov Int Learn Score
claude_code_generation 1.0 1.5 1.0 1.2 1.80
openai_codex 1.0 1.0 1.0 0.9 0.90
4

Select Best Tool

Winner: claude_code_generation with score 1.80

Claude-first bias (1.5x) + good learning history (1.2x) = highest score

5

Execute via Anthropic Adapter

AnthropicAdapter makes API call to Claude:

# Internal adapter call client.messages.create( model="claude-sonnet-4-20250514", messages=[{"role": "user", "content": task}], max_tokens=1024, )
6

Log Event (M3)

M3 Observability logs the execution:

{ "event": "tool_execution", "tool_id": "claude_code_generation", "provider": "anthropic", "success": true, "latency_ms": 1247, "tokens": {"input": 23, "output": 287} }
7

Update Learning (M5)

M5 stores the successful outcome:

  • Vector DB: Store task embedding for similarity search
  • Graph DB: Create Tool->Task->Success relationship
  • Learning boost for claude_code_generation: 1.2 -> 1.25
8

Return Response

MCPResponse

tool_used: claude_code_generation

provider: anthropic

tokens_used: TokenUsage(input=23, output=287)

result:

def fibonacci(n: int) -> int: """Calculate the nth Fibonacci number.""" if n <= 1: return n return fibonacci(n - 1) + fibonacci(n - 2)

What Happens Next Time?

When a similar task comes in (e.g., "Write a sorting function"):

  1. M5 finds similar past tasks via vector similarity
  2. claude_code_generation has boosted score (1.25x from learning)
  3. Tool selection is faster and more confident
  4. Success reinforces the learning boost further

Failure Scenario

If the tool fails (timeout, error, poor quality):

  1. M3 logs failure event
  2. M5 records negative outcome
  3. Learning boost decreases (e.g., 1.25 -> 1.15)
  4. If retry enabled, fallback to next-best tool
  5. Over time, unreliable tools get lower scores