anthropics / anthropics/claude-cookbooks
orchestrator_workers.ipynb: context dict is silently dropped from prompts
- 主要语言
- Jupyter Notebook
- 星标
- 52.7k
- 派生
- 6.3k
- 平均合并
- 25 分钟
- 30 天内合并 PR
- 6
描述
## Problem statement
In `patterns/agents/orchestrator_workers.ipynb`, `FlexibleOrchestrator.process()` passes the `context` dict into both prompt-building calls via `**context`:
```python
orchestrator_input = self._format_prompt(self.orchestrator_prompt, task=task, **context)
...
worker_input = self._format_prompt(
self.worker_prompt,
original_task=task,
task_type=task_info["type"],
task_description=task_info["description"],
**context,
)
```
But `ORCHESTRATOR_PROMPT` only defines `{task}`, and `WORKER_PROMPT` only defines `{original_task}`, `{task_type}`, `{task_description}`. Neither template references `{target_audience}` or `{key_features}` — the exact keys used in the notebook's own example call at the bottom of the notebook.
Since `str.format(**kwargs)` silently ignores any kwargs that don't match a placeholder in the template, `target_audience` and `key_features` never reach the model — the example appears to demonstrate context-aware generation but the context has no actual effect on the output.
This also creates a latent collision risk: if a `context` dict ever contained a key matching one of the fixed kwarg names (`task`, `original_task`, `task_type`, `task_description`), `_format_prompt` would raise `TypeError: got multiple values for keyword argument`.
## Proposed fix
Stop interpolating `context` into the prompt templates via named placeholders (which requires every template to declare every possible context key, and risks the kwarg collision above). Instead, render `context` as its own appended block regardless of which keys it contains:
```python
def _build_context_block(self, context: dict) -> str:
if not context:
return ""
lines = [f"{key}: {value}" for key, value in context.items()]
return "\n\nAdditional context:\n" + "\n".join(lines)
```
Then append this block to `orchestrator_input` / `worker_input` after formatting the fixed placeholders, rather than passing `**context` into `_format_prompt`. This way any context dict reaches the model regardless of its keys, and there's no more collision risk with fixed kwarg names.
## PR
Fixed in #836
贡献指南
评估
这个 Issue 还没有评估数据。