Skip to content

feat(agents): support expanded reasoning response in agent chat#2634

Open
ks93 wants to merge 5 commits into
masterfrom
feat/support-expanded-reasoning-response
Open

feat(agents): support expanded reasoning response in agent chat#2634
ks93 wants to merge 5 commits into
masterfrom
feat/support-expanded-reasoning-response

Conversation

@ks93

@ks93 ks93 commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Adds the data field to AgentReasoningItem, which the Agents API now returns to expose tool-call details from the agent's reasoning trace
  • Introduces ToolCallDetail, ReasoningDataItem, ToolCallReasoningDataItem, and UnknownReasoningDataItem following the same type-dispatch pattern as MessageContent/TextContent/UnknownContent
  • All four new classes are exported from cognite.client.data_classes.agents

API reference: https://api-docs.cognite.com/20230101-beta/tag/Agents/operation/agent_session_ai_agents_chat_post#!c=200&path=response/2/messages/reasoning/data&t=response

Test plan

Test manually locally.

  • pytest tests/tests_unit/test_api/test_agents_chat.py -v -- all 11 tests pass
  • Verify data=None is preserved when field is absent from the API response

@codecov

codecov Bot commented May 20, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.31250% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.04%. Comparing base (8a8a106) to head (5eac212).
⚠️ Report is 35 commits behind head on master.

Files with missing lines Patch % Lines
cognite/client/data_classes/agents/chat.py 94.91% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #2634      +/-   ##
==========================================
- Coverage   93.08%   93.04%   -0.04%     
==========================================
  Files         486      486              
  Lines       49671    49728      +57     
==========================================
+ Hits        46235    46271      +36     
- Misses       3436     3457      +21     
Files with missing lines Coverage Δ
cognite/client/data_classes/agents/__init__.py 100.00% <ø> (ø)
tests/tests_unit/test_api/test_agents_chat.py 100.00% <100.00%> (ø)
cognite/client/data_classes/agents/chat.py 97.52% <94.91%> (-0.60%) ⬇️

... and 6 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@ks93 ks93 changed the title feat: support expanded reasoning response in agent chat feat(agents): support expanded reasoning response in agent chat May 20, 2026
@ks93 ks93 force-pushed the feat/support-expanded-reasoning-response branch from 884f01b to 84f5b4d Compare May 20, 2026 15:47
Add the `data` field to `AgentReasoningItem` to surface tool-call details
from the agent's reasoning trace. Introduces `ToolCallDetail`,
`ReasoningDataItem`, `ToolCallReasoningDataItem`, and
`UnknownReasoningDataItem` following the same type-dispatch pattern used
by `MessageContent`.
@ks93 ks93 force-pushed the feat/support-expanded-reasoning-response branch from 84f5b4d to bda3637 Compare May 20, 2026 15:49
@ks93 ks93 marked this pull request as ready for review May 20, 2026 16:08
@ks93 ks93 requested review from a team as code owners May 20, 2026 16:08

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request introduces new data classes to support tool call reasoning data in agent chat responses, including ToolCallDetail and a ReasoningDataItem hierarchy. Review feedback focuses on reducing redundant serialization logic by leveraging base class functionality and ensuring that data loading methods are robust enough to handle both camelCase and snake_case keys for better compatibility.

Comment thread cognite/client/data_classes/agents/chat.py
Comment thread cognite/client/data_classes/agents/chat.py
Comment thread cognite/client/data_classes/agents/chat.py Outdated
- Remove manual ToolCallDetail.dump (base class handles camelCase conversion)
- Add dump to ReasoningDataItem base for consistency with MessageContent pattern
- Handle toolCall/tool_call key in ToolCallReasoningDataItem._load_item
@cognitedata cognitedata deleted a comment from gemini-code-assist Bot May 20, 2026
Comment thread cognite/client/data_classes/agents/chat.py Outdated
Comment thread cognite/client/data_classes/agents/chat.py Outdated
Comment thread cognite/client/data_classes/agents/chat.py Outdated
Comment thread cognite/client/data_classes/agents/chat.py Outdated

@haakonvt haakonvt 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.

A few comments, mostly LGTM

@haakonvt haakonvt 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.

LGTM

Comment thread cognite/client/data_classes/agents/chat.py
@haakonvt haakonvt added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label May 22, 2026
@ks93 ks93 enabled auto-merge May 22, 2026 07:24
@nithinb nithinb self-assigned this May 26, 2026
@nithinb nithinb added the risk-review-ongoing Risk review is in progress label May 26, 2026
@haakonvt

Copy link
Copy Markdown
Contributor

@nithinb ping 😄

@nithinb nithinb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I had a few comments, feel free to reach out once the changes are made.

def _load(cls, data: dict[str, Any]) -> AgentReasoningItem:
content = [MessageContent._load(item) for item in data.get("content", [])]
return cls(content=content)
data_items = [ReasoningDataItem._load(item) for item in data.get("data", [])] or None

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can data.get("data", []) be an empty list?
Because this silently converts an empty list to None. If it doesn't matter, I think a comment would be ideal in such scenarios

Comment on lines +560 to +562
data = data.copy()
item_type = data.pop("type")
return cls(type=item_type, data=data)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

nit and not blocking but generally it is better to store data.copy() in a separate variable instead of storing it in the same variable.

Like same name used for parameter and copy of the parameter.

Comment on lines +142 to 147
reasoning_item = agent_msg.reasoning[0]
assert isinstance(reasoning_item, AgentReasoningItem)
assert isinstance(reasoning_item.content[0], TextContent)
assert reasoning_item.data is not None
assert isinstance(reasoning_item.data[0], ToolCallReasoningDataItem)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think you should also add validation of actual data in reasoning_item.data and reasoning_item.content

@nithinb nithinb added waiting-for-team Waiting for the submitter or reviewer of the PR to take an action and removed waiting-for-risk-review Waiting for a member of the risk review team to take an action labels May 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk-review-ongoing Risk review is in progress waiting-for-team Waiting for the submitter or reviewer of the PR to take an action

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants