Skip to content

get_system_prompt(task) hook on LLMTaskWorker - #3

Merged
provos merged 2 commits into
mainfrom
system-prompt-hook
Sep 6, 2026
Merged

provos merged 2 commits into
mainfrom
system-prompt-hook

Conversation

@provos

@provos provos commented Sep 6, 2026

Copy link
Copy Markdown
Owner

Summary

Adds LLMTaskWorker.get_system_prompt(task), defaulting to the static system_prompt field, 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 reaches generate_pydantic as system
  • Used by databreach-explorer's report workers in production runs

🤖 Generated with Claude Code

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>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Sep 6, 2026 •

Copy link
Copy Markdown

Deploying planai with  Cloudflare Pages  Cloudflare Pages

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

View logs

Copilot AI lite review requested due to automatic review settings September 6, 2026 20:09
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Linting passed!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Example tests passed for deepsearch (Python 3.10)!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Tests passed for Python 3.11!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Tests passed for Python 3.10!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Tests passed for Python 3.12!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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 CachedLLMTaskWorker cache 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.

Comment thread src/planai/llm_task.py Outdated
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}"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread docs-astro/src/content/docs/api/taskworker.md Outdated
…the docs example

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Linting passed!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Example tests passed for deepsearch (Python 3.10)!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Tests passed for Python 3.11!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Tests passed for Python 3.12!

@github-actions

github-actions Bot commented Sep 6, 2026

Copy link
Copy Markdown

✅ Tests passed for Python 3.10!

@provos
provos merged commit c306999 into main Sep 6, 2026
11 checks passed
@provos
provos deleted the system-prompt-hook branch September 6, 2026 21:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants