Skip to content

chore: Moving some agent utils to utils file - #12238

Open
sjrl wants to merge 3 commits into
mainfrom
agent-util-refactor
Open

chore: Moving some agent utils to utils file#12238
sjrl wants to merge 3 commits into
mainfrom
agent-util-refactor

Conversation

@sjrl

@sjrl sjrl commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Related Issues

  • fixes #issue-number

Proposed Changes:

Some maintenance work to move some of the accumulated util functions in the agents.py to the utils.py file. The methods are all private so no risk of breaking imports.

How did you test it?

Moved tests as well to test_utils.py

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.

@sjrl
sjrl requested a review from a team as a code owner August 4, 2026 13:54
@sjrl
sjrl requested review from julian-risch and removed request for a team August 4, 2026 13:54
@vercel

vercel Bot commented Aug 4, 2026

Copy link
Copy Markdown

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 Aug 4, 2026 1:59pm

Request Review

@sjrl sjrl self-assigned this Aug 4, 2026
@sjrl sjrl added the ignore-for-release-notes PRs with this flag won't be included in the release notes. label Aug 4, 2026
@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  haystack/components/agents
  agent.py
  utils.py 80, 276
Project Total  

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

@julian-risch julian-risch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Changes look good to me in general. Only thing is that now no tests check that Agent still calls _validate_prompt_message_blocks.

I suggest that we add the following two tests back to TestPrompts in test_agent.py. Up to you if we just check for ValueError raised or if we match the message too. WDYT?

def test_prompt_wrong_role_raises_at_init(self, make_agent):
    with pytest.raises(ValueError, match="system_prompt message block must have role 'system'"):
        make_agent(system_prompt=_user_msg("This is a user message, not system."))
    with pytest.raises(ValueError, match="user_prompt message block must have role 'user'"):
        make_agent(user_prompt=_sys_msg("This is a system message, not user."))
def test_dynamic_prompt_role_raises_at_runtime(self, make_agent):
    agent = make_agent(user_prompt="{% message role=role_name %}Q: {{question}}{% endmessage %}")
    with pytest.raises(ValueError, match="user_prompt must render to a user message"):
        agent.run(messages=[], role_name="assistant", question="Will it snow?")

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

Labels

ignore-for-release-notes PRs with this flag won't be included in the release notes. topic:tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants