Skip to content

test: enable mypy typing checks for the agents tool-calling tests - #12755

Merged
davidsbatista merged 1 commit into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-agents-tool-calling
Sep 15, 2026
Merged

davidsbatista merged 1 commit into
deepset-ai:mainfrom
ShousenZHANG:test/type-check-agents-tool-calling

Conversation

@ShousenZHANG

Copy link
Copy Markdown
Contributor

Related Issues

Proposed Changes:

Adds test/components/agents/test_tool_calling.py and test_utils.py to the types target. Baseline was 24 errors. No suppressions — every one is fixed structurally.

  • 16 no-untyped-def. Eight are the missing -> None on TestSelectToolsByName, whose sibling tests in test_agent_hooks.py already carry it, plus configured_tools: ToolsType on the parametrized one, taken straight from _select_tools_by_name's own signature. The rest are return types on add_function, _reader_tool and _writer_tool, and the two ProblematicState.set overrides, which now repeat State.set's handler_override: Callable[[Any, Any], Any] | None rather than leaving it bare.
  • 6 union-attr. tool_messages[0].tool_call_result is optional. Narrowed once per test with assert tool_call_result is not None, rather than at each of the three attribute reads that follow — one line per test clears three errors.
  • 1 var-annotated on the seen accumulator.
  • 1 arg-type. ToolCallResult.result is a str or a sequence of content parts, so json.loads gets it through assert isinstance(result, str). That also makes the assertion state that the tool returned a string, which it previously took for granted.

test_agent.py is left out: it carries 82 of the directory's 106 errors on its own, including 27 from stubs that set was_warmed_up on Tool / Toolset, and belongs in its own PR.

How did you test it?

  • Before: mypy on the two files -> 24 errors. After: zero.
  • pytest on the two files -> 104 passed. Full unit suite -> 6399 passed. pytest -m integration test/components/agents/ -> 2 passed, 4 skipped, 0 failed.
  • ruff check / ruff format --check over the repo -> clean, 6804 files. check_imports.py -> 262 modules.
  • Two unit tests and one mypy error still fail on my machine and all three reproduce identically on a clean main checkout — a newer local openai than the tests expect, and the Windows mime registry. Neither is touched by this change.

No release note: test-only, which AGENTS.md excludes from the release-note requirement.


This PR was written with AI assistance.

@ShousenZHANG
ShousenZHANG requested a review from a team as a code owner September 15, 2026 02:54
@ShousenZHANG
ShousenZHANG requested review from davidsbatista and a lite review from Copilot and removed request for a team September 15, 2026 02:54
@vercel

vercel Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

@ShousenZHANG is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

Copy link
Copy Markdown
Contributor

Coverage report

This PR does not seem to contain any modification to coverable code.

Adds `test/components/agents/test_tool_calling.py` and `test_utils.py` to the
`types` target and fixes the 24 errors they surface. No suppressions: every one
is fixed structurally.

- 16 `no-untyped-def`. Eight are the missing `-> None` on `TestSelectToolsByName`,
  whose sibling tests in `test_agent_hooks.py` already carry it, plus
  `configured_tools: ToolsType` on the parametrized one, matching
  `_select_tools_by_name`. The rest are `add_function`, `_reader_tool` and
  `_writer_tool` return types and the two `ProblematicState.set` overrides, which
  now repeat `State.set`'s `handler_override: Callable[[Any, Any], Any] | None`.
- 6 `union-attr`. `tool_messages[0].tool_call_result` is optional; narrowed once
  per test with `assert tool_call_result is not None` instead of at each of the
  three attribute reads.
- 1 `var-annotated` on the `seen` accumulator.
- 1 `arg-type`. `ToolCallResult.result` is a `str` or a sequence of content parts,
  so `json.loads` gets it through `assert isinstance(result, str)`.

Part of #10396.
@ShousenZHANG
ShousenZHANG force-pushed the test/type-check-agents-tool-calling branch from b029be3 to 7fc1884 Compare September 15, 2026 06:29
@vercel

vercel Bot commented Sep 15, 2026 •

Copy link
Copy Markdown
Contributor

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

1 Skipped Deployment
Project Deployment Actions Updated
haystack-docs Ignored Ignored Preview Sep 15, 2026 9:43am UTC

Request Review

@davidsbatista davidsbatista left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

thanks 👍🏽

@davidsbatista
davidsbatista merged commit 605c8c0 into deepset-ai:main Sep 15, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants