Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions amplifier_core/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@

SESSION_RESUME = "session:resume"
LLM_REQUEST = "llm:request"
LLM_REQUEST_DEBUG = "llm:request:debug"
LLM_REQUEST_RAW = "llm:request:raw"
LLM_RESPONSE = "llm:response"
LLM_RESPONSE_DEBUG = "llm:response:debug"
LLM_RESPONSE_RAW = "llm:response:raw"
THINKING_DELTA = "thinking:delta"
THINKING_FINAL = "thinking:final"
CONTEXT_INCLUDE = "context:include"
Expand All @@ -76,7 +80,11 @@
PROVIDER_RESPONSE,
PROVIDER_ERROR,
LLM_REQUEST,
LLM_REQUEST_DEBUG,
LLM_REQUEST_RAW,
LLM_RESPONSE,
LLM_RESPONSE_DEBUG,
LLM_RESPONSE_RAW,
CONTENT_BLOCK_START,
CONTENT_BLOCK_DELTA,
CONTENT_BLOCK_END,
Expand Down
21 changes: 21 additions & 0 deletions docs/contracts/ORCHESTRATOR_CONTRACT.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,28 @@ async def execute(self, prompt, context, providers, tools, hooks):
"tool_input": tool_call.input,
"tool_result": result
})

# REQUIRED: At the end of execute(), emit orchestrator:complete
await hooks.emit("orchestrator:complete", {
"orchestrator": "my-orchestrator", # Your orchestrator name
"turn_count": iteration_count, # Number of LLM turns
"status": "success" # "success", "incomplete", or "cancelled"
})
```

#### Required: orchestrator:complete Event

**All orchestrators MUST emit `orchestrator:complete`** at the end of their `execute()` method. This event enables:
- Session analytics and debugging
- Hooks that trigger on turn completion (e.g., session naming)
- Observability and monitoring

| Field | Type | Description |
|-------|------|-------------|
| `orchestrator` | string | Name of the orchestrator module |
| `turn_count` | int | Number of LLM call iterations |
| `status` | string | Exit status: `"success"`, `"incomplete"`, or `"cancelled"` |

### Hook Processing

Handle HookResult actions:
Expand Down Expand Up @@ -295,6 +315,7 @@ Additional examples:
- [ ] Implements `execute(prompt, context, providers, tools, hooks) -> str`
- [ ] `mount()` function with entry point in pyproject.toml
- [ ] Emits standard events (provider:request/response, tool:pre/post)
- [ ] **Emits `orchestrator:complete` at the end of execute()**
- [ ] Handles HookResult actions appropriately
- [ ] Manages context (add messages, check compaction)

Expand Down