Skip to content

feat(agents): add QueryAgentTool (in preview) for the new data modeling query tool type#2569

Merged
haakonvt merged 12 commits into
masterfrom
feat/add-query-agent-tool
Apr 22, 2026
Merged

feat(agents): add QueryAgentTool (in preview) for the new data modeling query tool type#2569
haakonvt merged 12 commits into
masterfrom
feat/add-query-agent-tool

Conversation

@ks93
Copy link
Copy Markdown
Contributor

@ks93 ks93 commented Apr 16, 2026

Note

Stacked on #2584 (CI test skip), merge that first.

Summary

  • Adds first-class SDK support for the "query" agent tool type, which was previously deserialized as UnknownAgentTool
  • New classes: QueryAgentTool, QueryAgentToolUpsert, QueryAgentToolConfiguration
  • Configuration uses a flat data_models list (reusing DataModelInfo) with transparent API wrapping in dump/_load

Test plan

  • Unit tests added and passing (26 tests)

API not yet public, see
image
image

providedAtRuntime is not yet public.

@ks93 ks93 requested review from a team as code owners April 16, 2026 05:20
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

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 the QueryAgentTool, QueryAgentToolConfiguration, and QueryAgentToolUpsert classes to the Agents API, enabling flexible queries against data models. The changes include comprehensive documentation examples and unit tests for the new tool types. A review comment identifies a potential TypeError in the QueryAgentToolConfiguration._load method when handling null values for the dataModels key in API responses and provides a suggestion to improve the robustness of the parsing logic.

Comment thread cognite/client/data_classes/agents/agent_tools.py
@ks93 ks93 force-pushed the feat/add-query-agent-tool branch from 5085319 to dda47b6 Compare April 16, 2026 05:58
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.76%. Comparing base (ce76749) to head (11cb8b0).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2569   +/-   ##
=======================================
  Coverage   92.76%   92.76%           
=======================================
  Files         480      480           
  Lines       48446    48502   +56     
=======================================
+ Hits        44939    44991   +52     
- Misses       3507     3511    +4     
Files with missing lines Coverage Δ
cognite/client/_api/agents/agents.py 100.00% <ø> (ø)
cognite/client/_sync_api/agents/agents.py 100.00% <ø> (ø)
cognite/client/data_classes/agents/__init__.py 100.00% <ø> (ø)
cognite/client/data_classes/agents/agent_tools.py 98.66% <100.00%> (+0.33%) ⬆️
.../test_data_classes/test_agents/test_agent_tools.py 98.75% <100.00%> (+0.19%) ⬆️

... and 8 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 added the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Apr 16, 2026
Comment thread cognite/client/_api/agents/agents.py Outdated
Comment thread cognite/client/data_classes/agents/agent_tools.py Outdated
Comment thread cognite/client/data_classes/agents/agent_tools.py Outdated
Comment thread cognite/client/data_classes/agents/agent_tools.py
Comment thread cognite/client/data_classes/agents/agent_tools.py
Comment thread cognite/client/data_classes/agents/agents.py
Comment thread tests/tests_unit/test_api/test_agents.py
Comment thread tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py Outdated
ks93

This comment was marked as outdated.

@ks93 ks93 changed the base branch from master to feat/agents/add-runtime-version April 16, 2026 07:08
@ks93 ks93 force-pushed the feat/add-query-agent-tool branch from 9da3c4d to 6acddf4 Compare April 16, 2026 07:11
@ks93 ks93 requested a review from haakonvt April 16, 2026 07:34
@haakonvt haakonvt removed the waiting-for-risk-review Waiting for a member of the risk review team to take an action label Apr 16, 2026
Comment thread cognite/client/_api/agents/agents.py
Base automatically changed from feat/agents/add-runtime-version to master April 16, 2026 22:50
Copy link
Copy Markdown
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

Mostly LGTM. Should we add the query tool to the list of tools of the permanent agent in the integration test?

Comment thread tests/tests_unit/test_data_classes/test_agents/test_agent_tools.py Outdated
@ks93 ks93 changed the base branch from master to test/agent-tools-branch-on-expected-type April 18, 2026 00:42
@ks93 ks93 force-pushed the feat/add-query-agent-tool branch from 5cad072 to b3d722f Compare April 18, 2026 00:43
@ks93
Copy link
Copy Markdown
Contributor Author

ks93 commented Apr 18, 2026

Mostly LGTM. Should we add the query tool to the list of tools of the permanent agent in the integration test?

@haakonvt not yet, it is a bit in flux. Here's a stacked draft PR that we can merge in a few weeks: #2576

ks93 added a commit that referenced this pull request Apr 18, 2026
Exercises the new QueryAgentTool end-to-end via the shared integration test agent,
following review feedback on #2569.
Base automatically changed from test/agent-tools-branch-on-expected-type to master April 18, 2026 06:55

>>> from cognite.client.data_classes.agents import (
... AgentUpsert,
... QueryAgentToolUpsert,
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.

The current code raises due to "runtime version does not support it". I'm hesitant to merge code examples that don't work yet - I think the API change has to come first.

Copy link
Copy Markdown
Contributor Author

@ks93 ks93 Apr 21, 2026

Choose a reason for hiding this comment

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

Agree, fixed in cd05430. Filed APF-385 to drop the pinned runtime version once the Query tool lands in the default (non-preview) runtime

@ks93 ks93 changed the base branch from master to fix/skip-flaky-hosted-extractor-jobs-tests April 21, 2026 06:24
Copy link
Copy Markdown
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

@ks93 this gives me:

CogniteAPIError: Tool 'explore data' (type: query) requires a runtime version with Query Tool support
(for example 1.1.2-preview) and an experimental runtime. Current runtime version '1.1.3-preview' does
not support this tool. Please upgrade the agent's runtime version to use this tool. | code: 400 |
X-Request-ID: 1874c3ae-adf1-94a8-901c-eff9da9d9e56 | cluster: greenfield | project: forge-sandbox

The sentence Please upgrade the agent's runtime version to use this tool makes no sense 🤣

Base automatically changed from fix/skip-flaky-hosted-extractor-jobs-tests to master April 21, 2026 19:16
ks93 added 3 commits April 21, 2026 22:32
Tests were branching on isinstance(loaded_tool, ...), which is the
object under test. A loader regression returning the wrong subtype
could silently skip entire assertion blocks and still pass. Branching
on the parametrized expected_type keeps the isinstance check as a
real assertion.
Mirrors the pattern already used by test_agent_tool_load_returns_correct_subtype,
so a loader regression returning a wrong subtype fails loudly here instead of
relying on _type string equality alone.
The cog-ai backend and Fusion frontend already support the "query" tool
type, but the Python SDK deserialized it as UnknownAgentTool. This adds
first-class support with QueryAgentTool, QueryAgentToolUpsert, and
QueryAgentToolConfiguration classes.
ks93 added 6 commits April 21, 2026 22:33
Remove maturity label from docstring examples and surface missing
dataModels key instead of silently defaulting to empty dict.
Covered automatically by tests/tests_unit/test_base.py.
Covered by automatic load/dump tests in test_base.py. Keep only
test_load_without_configuration for the None config edge case.
Local codegen run during the rebase produced a stale hash; regenerated to match CI.
The current default runtime does not support the Query tool, so the
example would fail as written. Pin to 1.1.3-preview until the Query
tool lands in the default runtime.
@haakonvt haakonvt force-pushed the feat/add-query-agent-tool branch from 56a90b4 to 7a08a59 Compare April 21, 2026 20:33
@haakonvt haakonvt force-pushed the feat/add-query-agent-tool branch from 33c8067 to 11cb8b0 Compare April 21, 2026 20:54
Copy link
Copy Markdown
Contributor

@haakonvt haakonvt left a comment

Choose a reason for hiding this comment

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

🦄

@haakonvt haakonvt enabled auto-merge April 21, 2026 20:56
@haakonvt haakonvt changed the title feat: add QueryAgentTool for the query tool type feat(agents): add QueryAgentTool (in preview) for the new data modeling query tool type Apr 21, 2026
@haakonvt haakonvt added this pull request to the merge queue Apr 22, 2026
Merged via the queue into master with commit 31549a4 Apr 22, 2026
22 checks passed
@haakonvt haakonvt deleted the feat/add-query-agent-tool branch April 22, 2026 03:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants