feat(agents): add get_effective_system_prompt and stable instruction api#5841
feat(agents): add get_effective_system_prompt and stable instruction api#5841MoShiha wants to merge 3 commits into
Conversation
Confirm role, goal, backstory, system_template, and prompt_template as stable public API (safe to read and write after construction) by updating their Field descriptions in BaseAgent. Add Agent.get_effective_system_prompt() -> str, which returns the fully rendered system prompt as it would be sent to the LLM. Respects system_template and prompt_template overrides, and immediately reflects in-place writes to role, goal, and backstory. This is the read/write seam that DSPy optimizers and other instrumentation tools need to inspect and update agent instructions without patching internals. See: crewAIInc#5818 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughAdds Agent.get_effective_system_prompt(), expands BaseAgent field descriptions for role/goal/backstory as stable public API, and adds tests verifying read/write behavior and rendered system prompt content and template substitution. ChangesStable Agent Instruction API
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/crewai/src/crewai/agent/core.py`:
- Line 1297: The call currently coerces None to False by using
bool(self.use_system_prompt); change it to pass self.use_system_prompt through
unchanged so semantics match the runtime execution path. Locate the call in
creawi.agent.core (around the code that builds the prompt/request where
use_system_prompt is passed) and replace bool(self.use_system_prompt) with
self.use_system_prompt so None remains None and behavior is identical to the
actual execution path.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: e87848b7-a96a-4700-a5d6-02a915bb859a
📒 Files selected for processing (3)
lib/crewai/src/crewai/agent/core.pylib/crewai/src/crewai/agents/agent_builder/base_agent.pylib/crewai/tests/agents/test_agent_instruction_api.py
Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Confirm role, goal, backstory, system_template, and prompt_template as stable public API (safe to read and write after construction) by updating their Field descriptions in BaseAgent.
Add Agent.get_effective_system_prompt() -> str, which returns the fully rendered system prompt as it would be sent to the LLM. Respects system_template and prompt_template overrides, and immediately reflects in-place writes to role, goal, and backstory.
This is the read/write seam that DSPy optimizers and other instrumentation tools need to inspect and update agent instructions without patching internals. See: #5818
Summary by CodeRabbit
New Features
Documentation
Tests