feat(agents): add AgentSession for stateful multi-turn async conversations#2593
Draft
ks93 wants to merge 1 commit into
Draft
feat(agents): add AgentSession for stateful multi-turn async conversations#2593ks93 wants to merge 1 commit into
ks93 wants to merge 1 commit into
Conversation
…tions Adds `AgentSession` (async-only) and `AgentsAPI.create_session()` so callers on `AsyncCogniteClient` can conduct multi-turn conversations without manually threading the cursor between requests. - `create_session()` is a regular `def` (not async), which keeps it out of the codegen sync path entirely — the sync client is unchanged. - `AgentSession.chat()` advances the cursor only on success; failures leave it intact so the call can be retried safely. - `cursor=None` response retains the last non-null cursor. - Unknown kwargs to `create_session()` are silently accepted for forward compatibility.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2593 +/- ##
==========================================
+ Coverage 92.76% 92.79% +0.02%
==========================================
Files 480 481 +1
Lines 48511 48685 +174
==========================================
+ Hits 45003 45176 +173
- Misses 3508 3509 +1
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AgentSessionclass (cognite/client/data_classes/agents/session.py) that stores agent external ID, actions, and conversation cursor for multi-turn async chat.AgentsAPI.create_session()as a plaindeffactory method (notasync def) — this keeps it out of the codegen sync path, so the sync client is untouched.AgentSession.chat()automatically threads the cursor from each response into the next request; callers manage only messages, not cursor state.Behavior
await session.chat(...)leaves the cursor intact so the call can be retried.null/missing cursor in the response retains the last known cursor.create_session()are silently accepted for forward compatibility.AgentSessionis exported fromcognite.client.data_classes.agents.Test plan
tests/tests_unit/test_api/test_agents.pycovering cursor threading, failure isolation, null-cursor retention, actions forwarding, action-result round-trips,ToolConfirmationCallpass-through, and scope guards (read-only cursor, sync client exclusion, noresetmethod)hasattr(sync_client.agents, "create_session") is False_sync_api/agents/agents.pyhas no new methods (hash-only update)