Skip to content

Commit 2d903d6

Browse files
committed
Expose conversation ID to agents for conversation continuity
- Capture conversation ID from metadata events in streaming response - Append conversation ID to response for new conversations - Log conversation ID for debugging - Agents can now see and use conversation IDs for follow-up questions This enables proper conversation continuity - agents receive the conversation ID after their first question and can use it in subsequent calls.
1 parent c70753d commit 2d903d6

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/tools/chat.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,22 +117,42 @@ async def codebase_consultant(
117117

118118
# Process streaming response - we always stream internally for efficiency
119119
full_response = ""
120+
conversation_metadata = {}
121+
120122
async for line in response.aiter_lines():
121123
if not line:
122124
continue
123125

126+
# Handle metadata events
127+
if line.startswith("event: message"):
128+
continue
129+
124130
if line.startswith("data: "):
125131
data = line[6:] # Remove "data: " prefix
126132
if data == "[DONE]":
127133
break
128134
try:
129135
chunk = json.loads(data)
136+
137+
# Capture metadata with conversation ID
138+
if chunk.get("event") == "metadata" and "conversationId" in chunk:
139+
conversation_metadata = chunk
140+
await ctx.info(f"Conversation ID: {chunk['conversationId']}")
141+
continue
142+
143+
# Process content chunks
130144
if "choices" in chunk and len(chunk["choices"]) > 0:
131145
delta = chunk["choices"][0].get("delta", {})
132146
if delta and "content" in delta and delta["content"] is not None:
133147
full_response += delta["content"]
134148
except json.JSONDecodeError:
135149
pass
150+
151+
# Append conversation ID info to the response if we got one and it's a new conversation
152+
if conversation_metadata.get("conversationId") and not conversation_id:
153+
conversation_id_note = f"\n\n---\n**Conversation ID:** `{conversation_metadata['conversationId']}`\n*Use this ID in the `conversation_id` parameter to continue this conversation.*"
154+
full_response += conversation_id_note
155+
136156
return full_response or "No content returned from the API. Please check that your data sources are accessible and try again."
137157

138158
except (httpx.HTTPStatusError, Exception) as e:

0 commit comments

Comments
 (0)