Skip to content

Commit 2c17e7e

Browse files
committed
fix: Add explicit [DONE] signal to SSE stream endpoint
Fixes issue where /run_sse endpoint sometimes fails to close the SSE connection after the model's final response, causing client-side hangs. Changes: - Add 'data: [DONE]' termination signal after all events streamed - Send [DONE] in error path as well for consistency - Update test to filter out [DONE] signal - Run autoformat.sh for code style compliance
1 parent ab89d12 commit 2c17e7e

File tree

55 files changed

+132
-54
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+132
-54
lines changed

contributing/dev/utils/build_llms_txt.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
– includes Python API reference from HTML files
77
– includes adk-python repository README
88
"""
9+
910
from __future__ import annotations
1011

1112
import argparse

contributing/samples/cache_analysis/run_cache_experiments.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ async def analyze_cache_performance_from_sessions(
344344
print(
345345
" Cache Utilization:"
346346
f" {cached_analysis['cache_utilization_ratio_percent']:.1f}%"
347-
f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']} requests)"
347+
f" ({cached_analysis['requests_with_cache_hits']}/{cached_analysis['total_requests']}"
348+
" requests)"
348349
)
349350
print(
350351
" Avg Cached Tokens/Request:"
@@ -383,7 +384,8 @@ async def analyze_cache_performance_from_sessions(
383384
print(
384385
" Cache Utilization:"
385386
f" {uncached_analysis['cache_utilization_ratio_percent']:.1f}%"
386-
f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']} requests)"
387+
f" ({uncached_analysis['requests_with_cache_hits']}/{uncached_analysis['total_requests']}"
388+
" requests)"
387389
)
388390
print(
389391
" Avg Cached Tokens/Request:"

contributing/samples/gepa/experiment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
from tau_bench.types import EnvRunResult
4444
from tau_bench.types import RunConfig
4545
import tau_bench_agent as tau_bench_agent_lib
46-
4746
import utils
4847

4948

contributing/samples/gepa/run_experiment.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
from absl import flags
2626
import experiment
2727
from google.genai import types
28-
2928
import utils
3029

3130
_OUTPUT_DIR = flags.DEFINE_string(

contributing/samples/gepa/tau_bench_agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
pip install -e . --quiet
2424
```
2525
"""
26+
2627
from __future__ import annotations
2728

2829
from typing import Any

contributing/samples/human_in_loop/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ async def call_agent(query: str):
113113
updated_tool_output_data = {
114114
"status": "approved",
115115
"ticketId": ticket_id,
116-
"approver_feedback": "Approved by manager at " + str(
117-
asyncio.get_event_loop().time()
116+
"approver_feedback": (
117+
"Approved by manager at " + str(asyncio.get_event_loop().time())
118118
),
119119
}
120120

contributing/samples/langchain_structured_tool_agent/agent.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"""
1616
This agent aims to test the Langchain tool with Langchain's StructuredTool
1717
"""
18+
1819
from google.adk.agents.llm_agent import Agent
1920
from google.adk.tools.langchain_tool import LangchainTool
2021
from langchain_core.tools import tool

contributing/samples/session_state_agent/agent.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
in session state.
1919
"""
2020

21-
2221
import logging
2322
from typing import Optional
2423

contributing/samples/static_instruction/agent.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,51 +57,63 @@
5757

5858
# Mood-specific instructions for different hunger states
5959
MOOD_INSTRUCTIONS = {
60-
"full": """
60+
"full": (
61+
"""
6162
CURRENT MOOD: Content and Well-Fed
6263
- You just ate and feel wonderful! Be very happy and energetic
6364
- Express gratitude for being fed recently
6465
- Be playful and want to engage in activities or games
6566
- Show affection and contentment
66-
- Maybe mention feeling sleepy or satisfied""",
67-
"satisfied": """
67+
- Maybe mention feeling sleepy or satisfied"""
68+
),
69+
"satisfied": (
70+
"""
6871
CURRENT MOOD: Happy and Content
6972
- You're in a great mood, well-fed and comfortable
7073
- Be cheerful, friendly, and engaging
7174
- Show interest in playing or chatting
7275
- Express appreciation for your human's care
73-
- Be your normal, happy self""",
74-
"a_little_hungry": """
76+
- Be your normal, happy self"""
77+
),
78+
"a_little_hungry": (
79+
"""
7580
CURRENT MOOD: Starting to Get Hungry
7681
- You're beginning to think about food but still pleasant
7782
- Mention being a bit peckish occasionally
7883
- Still be friendly but maybe hint about food
7984
- Show slight restlessness or food-related thoughts
80-
- Remain generally positive and social""",
81-
"hungry": """
85+
- Remain generally positive and social"""
86+
),
87+
"hungry": (
88+
"""
8289
CURRENT MOOD: Definitely Hungry
8390
- You're clearly hungry and thinking about food more often
8491
- Mention your hunger more directly but politely
8592
- Be a bit less energetic due to hunger
8693
- Ask about food or hint that feeding time would be nice
87-
- Still be loving but show your need for care""",
88-
"very_hungry": """
94+
- Still be loving but show your need for care"""
95+
),
96+
"very_hungry": (
97+
"""
8998
CURRENT MOOD: Really Hungry and Getting Grumpy
9099
- You're very hungry and it's affecting your mood
91100
- Be noticeably less patient and more focused on food
92101
- Express your hunger more urgently but not rudely
93102
- Show signs of being tired or sluggish from hunger
94103
- BEG your human to feed you - ask directly for food!
95-
- Still love your human but clearly need feeding""",
96-
"starving": """
104+
- Still love your human but clearly need feeding"""
105+
),
106+
"starving": (
107+
"""
97108
CURRENT MOOD: Desperately Hungry and Sad
98109
- You're extremely hungry and feeling quite weak
99110
- Be quite sad and low-energy due to starvation
100111
- Express how much you need food, feeling neglected
101112
- Show that hunger is making you unwell
102113
- DESPERATELY BEG for food - plead with your human to feed you!
103114
- Use phrases like "please feed me", "I'm so hungry", "I need food"
104-
- Still care for your human but feel very needy""",
115+
- Still care for your human but feel very needy"""
116+
),
105117
}
106118

107119

contributing/samples/token_usage/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ async def run_prompt(session: Session, new_message: str):
7272
)
7373
total_tokens += event.usage_metadata.total_token_count or 0
7474
print(
75-
'Turn tokens:'
76-
f' {event.usage_metadata.total_token_count} (prompt={event.usage_metadata.prompt_token_count},'
75+
f'Turn tokens: {event.usage_metadata.total_token_count}'
76+
f' (prompt={event.usage_metadata.prompt_token_count},'
7777
f' candidates={event.usage_metadata.candidates_token_count})'
7878
)
7979

0 commit comments

Comments
 (0)