Repository navigation
get_system_prompt(task) hook on LLMTaskWorker - #3
Conversation
Lets a worker build a per-task system prompt, e.g. to put reference material shared by many tasks into the system block where the provider's prompt cache can reuse it across tasks. Used by the cache key as well. Version 0.7.1. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Deploying planai with
|
| Latest commit: |
0c46a86
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://080a7cc7.planai-bae.pages.dev |
| Branch Preview URL: | https://system-prompt-hook.planai-bae.pages.dev |
|
✅ Linting passed! |
|
✅ Example tests passed for deepsearch (Python 3.10)! |
|
✅ Tests passed for Python 3.11! |
|
✅ Tests passed for Python 3.10! |
|
✅ Tests passed for Python 3.12! |
There was a problem hiding this comment.
🟡 Changes recommended
There are a couple of concrete fixable issues (notably a docs example that can raise a TypeError when system_prompt is None, and a redundant per-task hook invocation in the cache key path) that should be addressed before merging.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Adds a per-task get_system_prompt(task) hook to LLMTaskWorker, enabling dynamic system prompts (notably for provider prompt caching) while preserving existing behavior by defaulting to the system_prompt field.
Changes:
- Introduces
LLMTaskWorker.get_system_prompt(task)and routes LLM calls through it. - Updates
CachedLLMTaskWorkercache key composition to incorporate the per-task system prompt. - Adds unit tests and updates docs + bumps version to 0.7.1.
File summaries
| File | Description |
|---|---|
src/planai/llm_task.py |
Adds get_system_prompt(task) and uses it in request building and cache key generation. |
tests/planai/test_llm_task.py |
Adds tests verifying the hook is invoked and defaults to the field value. |
docs-astro/src/content/docs/features/llm-integration.md |
Documents the new per-task system prompt hook for LLM integration usage. |
docs-astro/src/content/docs/api/taskworker.md |
Adds API reference example for get_system_prompt. |
src/planai/_version.py |
Bumps internal package version to 0.7.1. |
pyproject.toml |
Bumps Poetry package version to 0.7.1. |
Review details
- Files reviewed: 6/6 changed files
- Comments generated: 2
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| upstream_cache_key = super()._get_cache_key(task) | ||
|
|
||
| upstream_cache_key += f" - {self.system_prompt} - {self.get_full_prompt(task)} - {self.llm.model_name}" | ||
| upstream_cache_key += f" - {self.get_system_prompt(task)} - {self.get_full_prompt(task)} - {self.llm.model_name}" |
There was a problem hiding this comment.
Partly: generate_full_prompt() ignores its system argument, so the full prompt does not contain the system prompt and it has to stay in the key explicitly. What was redundant is the double evaluation: the key now evaluates get_system_prompt(task) once and passes it to get_full_prompt(task, system_prompt=...). Test added asserting a single call.
…the docs example Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
✅ Linting passed! |
|
✅ Example tests passed for deepsearch (Python 3.10)! |
|
✅ Tests passed for Python 3.11! |
|
✅ Tests passed for Python 3.12! |
|
✅ Tests passed for Python 3.10! |
Summary
Adds
LLMTaskWorker.get_system_prompt(task), defaulting to the staticsystem_promptfield, used for the request and for the cache key.The motivation is prompt caching: Anthropic matches cached prefixes at content-block boundaries and llm-interface sends a user message as one block, so reference material that many tasks share (databreach-explorer puts the notes for a breach in front of every drafting, review and fix conversation) can only be served from the cache across tasks when it lives in the system block. The material does not exist until mid-graph and a worker instance serves every task, hence a per-task hook rather than a field.
Documented in docs-astro (API reference and LLM integration page). Version 0.7.1.
Test plan
pytest tests/planai: hook is called with the task and its value reachesgenerate_pydanticassystem🤖 Generated with Claude Code