Skip to content

feat: rework tool calling#753

Open
maksymbuleshnyi wants to merge 15 commits into
mainfrom
feat/rework-tool-calling
Open

feat: rework tool calling#753
maksymbuleshnyi wants to merge 15 commits into
mainfrom
feat/rework-tool-calling

Conversation

@maksymbuleshnyi
Copy link
Copy Markdown
Contributor

@maksymbuleshnyi maksymbuleshnyi commented May 26, 2026

Note

High Risk
Touches core agent LLM invocation, tool schema generation, multi-provider strict transforms, and streaming parsers—behavior changes for all inference modes and can alter model outputs and tool validation.

Overview
This PR reworks agent tool calling end-to-end: schemas, provider transforms, parsing, and streaming alignment.

Schemas & prompts: Structured-output action_input is now a JSON object (finish uses {"answer": "..."}); generator-level strict flags are removed in favor of per-provider handling. ReAct/XML prompts add stricter single-turn rules; function-calling loops default to tool_choice: required when tools are present (unless overridden).

Provider strict mode: BaseLLM.strict_tools (bool or allowlist) drives transform_tool_schemas on OpenAI and Anthropic—schema cleaning, optional→nullable encoding, free-form dict fields as JSON strings, and strict: true where supported. Anthropic adds LiteLLM patching to forward strict and caps strict tools per request.

Agent post-processing: After tool calls, inputs are coerced (stringified dicts, including nested models) and protocol nulls stripped before Pydantic validation; truncated tool JSON can be repaired via repair_truncated_json. Structured-output finish reads action_input["answer"] when present.

Streaming: Structured-output initialization avoids locking onto the raw action_input object for answers (fixes leaking {"answer": ...} in streams); integration FSM assertions account for strict null defaults in streamed tool input.

Reviewed by Cursor Bugbot for commit 6f4e213. Bugbot is set up for automated code reviews on this repo. Configure here.

@maksymbuleshnyi maksymbuleshnyi requested a review from a team as a code owner May 26, 2026 20:26
Comment thread dynamiq/nodes/agents/agent.py Outdated
Comment thread dynamiq/nodes/llms/anthropic.py Outdated
Comment thread dynamiq/nodes/llms/anthropic.py Outdated
Comment thread dynamiq/nodes/agents/agent.py Outdated
Comment thread dynamiq/nodes/agents/agent.py Outdated
Comment thread dynamiq/nodes/llms/openai.py
Comment thread dynamiq/nodes/llms/openai.py
Comment thread dynamiq/nodes/llms/openai.py
Comment thread dynamiq/nodes/llms/openai.py
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 28, 2026

Coverage

Coverage Report •
FileStmtsMissCoverMissing
dynamiq/callbacks
   streaming.py6446190%22, 189, 202–203, 211–212, 228–229, 267–268, 276, 303–309, 313, 321–326, 334, 342–343, 395, 399, 403, 445, 448, 502, 566, 570, 623, 663–666, 694–695, 778–781, 903–904, 990, 1017, 1097, 1154–1159, 1195, 1199, 1230
dynamiq/nodes/agents
   agent.py95718780%83–87, 330–335, 340–347, 352–359, 380, 382–393, 413, 418–425, 440–443, 448, 464–465, 483–484, 506, 513–514, 521–522, 528–529, 531, 590–592, 802–804, 819, 828, 854, 870, 889, 902–905, 907, 933–934, 936, 956, 968, 973, 988, 996–997, 1007, 1010, 1020, 1060–1062, 1068–1070, 1179, 1184, 1235, 1269, 1271, 1286–1287, 1294, 1297, 1324–1325, 1341, 1380, 1407–1411, 1478, 1484, 1488, 1491, 1525, 1553, 1556, 1561, 1577, 1651–1652, 1687, 1692, 1716, 1772, 1794–1796, 1799–1800, 1810, 1813, 1823, 1830, 1880–1883, 1903–1904, 1908, 1910–1912, 1914, 1916, 1949, 1957–1958, 1960, 1963, 1966, 2017–2020, 2036, 2045, 2110, 2116–2122, 2128, 2130–2139, 2141–2142
dynamiq/nodes/agents/components
   schema_generator.py1643876%61, 64, 139, 252, 256, 261–266, 269–271, 276, 280–281, 283–291, 293, 308, 310, 321–322, 356–357, 359, 364–365, 401, 418
dynamiq/nodes/llms
   anthropic.py1449236%32–34, 38–39, 43–44, 47, 50–57, 59–60, 118–119, 121–125, 130–134, 137–142, 147–155, 158–160, 162, 166–171, 173–175, 177, 217, 227–233, 240, 242, 244, 284–285, 287–306
   base.py4164589%34, 36, 153, 159, 351, 397–400, 409–415, 442, 488, 531–532, 536, 634–643, 664–665, 680, 718, 720, 754, 756, 823, 886, 985, 1061, 1064, 1095–1096
   openai.py1729942%43–54, 69–70, 72–81, 83–91, 96–100, 102, 105–107, 109–110, 115–116, 120–135, 153–156, 158–165, 167, 173–175, 177–179, 300–312, 317–321
dynamiq/utils
   json_parser.py1344070%28–29, 47, 90–91, 135–136, 201–202, 204–206, 208–224, 226–228, 230–234, 236–237, 239
TOTAL32824973270% 

Tests Skipped Failures Errors Time
2376 2 💤 0 ❌ 0 🔥 2m 42s ⏱️

@maksymbuleshnyi maksymbuleshnyi added the run-integration-tests-with-creds Trigger integration tests with credentials (optional) label May 28, 2026
@tyaroshko tyaroshko added run-integration-tests-with-creds Trigger integration tests with credentials (optional) and removed run-integration-tests-with-creds Trigger integration tests with credentials (optional) labels May 29, 2026
Comment thread dynamiq/nodes/llms/openai.py
Comment thread dynamiq/nodes/llms/openai.py
Comment thread dynamiq/nodes/agents/agent.py
Comment thread dynamiq/callbacks/streaming.py
Comment thread dynamiq/nodes/agents/agent.py
@maksymbuleshnyi maksymbuleshnyi added run-integration-tests-with-creds Trigger integration tests with credentials (optional) and removed run-integration-tests-with-creds Trigger integration tests with credentials (optional) labels May 29, 2026
@maksymbuleshnyi maksymbuleshnyi removed the run-integration-tests-with-creds Trigger integration tests with credentials (optional) label May 29, 2026
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 1e2e9b1. Configure here.

Comment thread dynamiq/nodes/agents/agent.py Outdated
@maksymbuleshnyi maksymbuleshnyi added the run-integration-tests-with-creds Trigger integration tests with credentials (optional) label May 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-integration-tests-with-creds Trigger integration tests with credentials (optional)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants