Skip to content

Commit 64b758a

Browse files
GWealecopybara-github
authored andcommitted
fix: derive an SDK-conforming Antigravity conversation id
The Antigravity SDK now requires conversation_id to be at least 32 characters and match [a-zA-Z0-9-]. The wrapper built it as "{session_id}_{agent_name}", which is too short and contains underscores, so resuming a conversation raised a ValidationError. Derive it from a hash of the session id and agent name instead, so it stays deterministic (trajectories still resume) while always meeting the constraints. Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 949741204
1 parent c429d75 commit 64b758a

2 files changed

Lines changed: 15 additions & 4 deletions

File tree

src/google/adk/labs/antigravity/_antigravity_agent.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
from __future__ import annotations
2929

30+
import hashlib
3031
import logging
3132
from typing import Any
3233
from typing import AsyncGenerator
@@ -54,6 +55,13 @@
5455
)
5556

5657

58+
def _derive_conversation_id(session_id: str, agent_name: str) -> str:
59+
"""Returns a deterministic conversation id (>=32 chars, [a-zA-Z0-9-])."""
60+
# Hashing keeps the id stable across turns (so trajectories resume) while
61+
# always satisfying the Antigravity SDK's length and character constraints.
62+
return hashlib.sha256(f'{session_id}/{agent_name}'.encode()).hexdigest()
63+
64+
5765
class AntigravityAgent(BaseAgent):
5866
"""Runs a Google Antigravity SDK agent as an ADK root agent.
5967
@@ -114,7 +122,7 @@ async def _run_async_impl(
114122
# The SDK Agent's AsyncExitStack is single-use, so a new instance is needed
115123
# per turn; copying also avoids mutating the caller's config.
116124
config = self.config.model_copy(deep=True)
117-
conversation_id = f'{ctx.session.id}_{self.name}'
125+
conversation_id = _derive_conversation_id(ctx.session.id, self.name)
118126

119127
# Resume only when a trajectory already exists; the harness errors if a
120128
# conversation_id is given with no matching file on disk.

tests/unittests/labs/antigravity/test_antigravity_agent.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,19 @@ async def _receive_steps():
9595
conversation = MagicMock()
9696
conversation.send = AsyncMock()
9797
conversation.receive_steps = _receive_steps
98+
conversation_id = _antigravity_agent._derive_conversation_id(
99+
'sess_456', 'agy'
100+
)
98101
active_agent = MagicMock()
99102
active_agent.conversation = conversation
100-
active_agent.conversation_id = 'sess_456_agy'
103+
active_agent.conversation_id = conversation_id
101104
active_agent.__aenter__ = AsyncMock(return_value=active_agent)
102105
active_agent.__aexit__ = AsyncMock(return_value=None)
103106

104107
# A prior trajectory + resume index in save_dir triggers resume at index 1.
105108
save_dir = tmp_path
106-
(save_dir / 'traj-sess_456_agy').write_bytes(b'data')
107-
(save_dir / 'traj-sess_456_agy.resume').write_text('1')
109+
(save_dir / f'traj-{conversation_id}').write_bytes(b'data')
110+
(save_dir / f'traj-{conversation_id}.resume').write_text('1')
108111
agent = AntigravityAgent(
109112
name='agy', config=_make_config(save_dir=str(save_dir))
110113
)

0 commit comments

Comments
 (0)