Skip to content

refactor!: Remove user_prompt and system_prompt from Agent.run#11209

Draft
sjrl wants to merge 7 commits intosingle-tracing-span-per-loopfrom
remove-user-system-prompt-runtime
Draft

refactor!: Remove user_prompt and system_prompt from Agent.run#11209
sjrl wants to merge 7 commits intosingle-tracing-span-per-loopfrom
remove-user-system-prompt-runtime

Conversation

@sjrl
Copy link
Copy Markdown
Contributor

@sjrl sjrl commented Apr 28, 2026

Related Issues

  • WIP just experimenting

Proposed Changes:

Remove the user_prompt and system_prompt from the Agent's run method to reduce the complexity of how the Agent can be called. With these changes it becomes more obvious that new runtime content should either be passed through into messages param or any of the kwargs that are exposed via prompt template variables from the system_prompt and user_prompt passed in at init time.

The original motivation for exposing the user and system prompts as runtime variables was to enable the Prompt Explorer in our cloud platform which needed these runtime params to easily update/explore different prompts. However, they will no longer be needed to enable that feature in the near future.

How did you test it?

Notes for the reviewer

Checklist

  • I have read the contributors guidelines and the code of conduct.
  • I have updated the related issue with new insights and changes.
  • I have added unit tests and updated the docstrings.
  • I've used one of the conventional commit types for my PR title: fix:, feat:, build:, chore:, ci:, docs:, style:, refactor:, perf:, test: and added ! in case the PR includes breaking changes.
  • I have documented my code.
  • I have added a release note file, following the contributors guidelines.
  • I have run pre-commit hooks and fixed any issue.

@vercel
Copy link
Copy Markdown

vercel Bot commented Apr 28, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
haystack-docs Ignored Ignored Preview Apr 28, 2026 10:38am

Request Review

@github-actions github-actions Bot added topic:tests type:documentation Improvements on the docs labels Apr 28, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 28, 2026

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/agents
  agent.py
  haystack/human_in_the_loop
  strategies.py
Project Total  

This report was generated by python-coverage-comment-action

@sjrl sjrl changed the title Remove user system prompt runtime refactor!: Remove user_prompt and system_prompt from Agent.run Apr 28, 2026
@sjrl sjrl force-pushed the single-tracing-span-per-loop branch from 155b0d1 to bde728d Compare April 28, 2026 08:38
sjrl added 2 commits April 28, 2026 12:19
…haystack into remove-user-system-prompt-runtime
…haystack into remove-user-system-prompt-runtime
@anakin87
Copy link
Copy Markdown
Member

Just dropping here a more radical (untested) idea

  • allow only system_prompt in the __init__
  • let users pass messages as list[ChatMessage] | str in run to allow Jinja 2 interpolation
  • improve ChatPromptBuilder handling, which is messy right now

WDYT?

@sjrl
Copy link
Copy Markdown
Contributor Author

sjrl commented Apr 29, 2026

Just dropping here a more radical (untested) idea

  • allow only system_prompt in the __init__
  • let users pass messages as list[ChatMessage] | str in run to allow Jinja 2 interpolation
  • improve ChatPromptBuilder handling, which is messy right now

WDYT?

Interesting idea. Only thing I can think of as a potential problem is that if user prompt can only be at runtime then we would lose the ability to connect user prompt variables when building the pipeline.

Maybe rename user_prompt to user_prompt_template to help emphasize it's meant to be for templating and not be a normal user message?

@sjrl
Copy link
Copy Markdown
Contributor Author

sjrl commented Apr 29, 2026

Or maybe more radical we throw away system and user prompt at init time and just a generic messages_template which would be a jinja2 template that would default to {{messages}} which serves as a placeholder for the messages provided at runtime. Then users could add a system message and or a user message around the messages placeholder. Would have to think this through more but wdyt?

@anakin87
Copy link
Copy Markdown
Member

Or maybe more radical we throw away system and user prompt at init time and just a generic messages_template which would be a jinja2 template that would default to {{messages}} which serves as a placeholder for the messages provided at runtime. Then users could add a system message and or a user message around the messages placeholder. Would have to think this through more but wdyt?

Not a bad idea.

In general, I thought that keeping system_prompt in __init__ can be convenient for users.

But feel free to explore your idea further...

@sjrl
Copy link
Copy Markdown
Contributor Author

sjrl commented Apr 29, 2026

Or maybe more radical we throw away system and user prompt at init time and just a generic messages_template which would be a jinja2 template that would default to {{messages}} which serves as a placeholder for the messages provided at runtime. Then users could add a system message and or a user message around the messages placeholder. Would have to think this through more but wdyt?

Not a bad idea.

In general, I thought that keeping system_prompt in __init__ can be convenient for users.

But feel free to explore your idea further...

That's fair about system_prompt. I'll note this idea down in our notion page and aim to tackle it in a future PR. For now I think we can move forward with this simplification and revisit this idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic:tests type:documentation Improvements on the docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants