Skip to content

Commit 32dd78e

Browse files
committed
test: fix sys.modules stub leakage and apply repo formatting
test_claude_agents_* now remove their placeholder packages after loading, which previously blocked real imports of the temporal plugin tree in later-collected tests. Formats touched files with ruff and narrows span.output types in new tests for pyright.
1 parent 4d1ff90 commit 32dd78e

12 files changed

Lines changed: 297 additions & 261 deletions

File tree

src/agentex/lib/adk/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,11 @@
4141
"events",
4242
"agent_task_tracker",
4343
"TurnSpan",
44-
4544
# Checkpointing / LangGraph
4645
"create_checkpointer",
4746
"create_langgraph_tracing_handler",
4847
"stream_langgraph_events",
4948
"convert_langgraph_to_agentex_events",
50-
5149
# Providers
5250
"providers",
5351
# Utils

src/agentex/lib/adk/_modules/_langgraph_tracing.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
from agentex.types.span import Span
1515
from agentex.lib.utils.logging import make_logger
16-
from agentex.lib.adk._modules.tracing import TracingModule
1716
from agentex.lib.core.tracing.usage import usage_from_counts
17+
from agentex.lib.adk._modules.tracing import TracingModule
1818

1919
logger = make_logger(__name__)
2020

@@ -251,11 +251,7 @@ def _extract_usage(response: LLMResult, msg: Any) -> dict[str, Any] | None:
251251
llm_output = getattr(response, "llm_output", None) or {}
252252
token_usage = llm_output.get("token_usage") or llm_output.get("usage")
253253
if isinstance(token_usage, dict) and token_usage:
254-
return {
255-
key: value
256-
for key, value in token_usage.items()
257-
if isinstance(value, (int, float))
258-
}
254+
return {key: value for key, value in token_usage.items() if isinstance(value, (int, float))}
259255
return None
260256

261257

src/agentex/lib/adk/_modules/tracing.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,7 @@ async def turn_span(
234234
235235
Example::
236236
237-
async with adk.tracing.turn_span(
238-
trace_id=task.id, name="turn", input={...}, task_id=task.id
239-
) as turn:
237+
async with adk.tracing.turn_span(trace_id=task.id, name="turn", input={...}, task_id=task.id) as turn:
240238
result = await run_llm_calls()
241239
turn.output = {"response": result.text}
242240
turn.record_usage(usage=result.usage, cost_usd=result.cost_usd)

src/agentex/lib/core/services/adk/providers/litellm.py

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,7 @@ async def chat_completion_auto_send(
114114
),
115115
) as streaming_context:
116116
completion = await self.llm_gateway.acompletion(**llm_config.model_dump())
117-
if (
118-
completion.choices
119-
and len(completion.choices) > 0
120-
and completion.choices[0].message
121-
):
117+
if completion.choices and len(completion.choices) > 0 and completion.choices[0].message:
122118
final_content = TextContent(
123119
author="agent",
124120
content=completion.choices[0].message.content or "",
@@ -178,9 +174,7 @@ async def chat_completion_stream(
178174
) as span:
179175
# Direct streaming outside temporal - yield each chunk as it comes
180176
chunks: list[Completion] = []
181-
async for chunk in self.llm_gateway.acompletion_stream(
182-
**completion_kwargs
183-
):
177+
async for chunk in self.llm_gateway.acompletion_stream(**completion_kwargs):
184178
chunks.append(chunk)
185179
yield chunk
186180
if span:
@@ -231,18 +225,12 @@ async def chat_completion_stream_auto_send(
231225
) as streaming_context:
232226
# Get the streaming response
233227
chunks = []
234-
async for response in self.llm_gateway.acompletion_stream(
235-
**completion_kwargs
236-
):
228+
async for response in self.llm_gateway.acompletion_stream(**completion_kwargs):
237229
heartbeat_if_in_workflow("chat completion streaming")
238230
# Store every chunk for final message assembly, including
239231
# the usage-only final chunk, which has no choices
240232
chunks.append(response)
241-
if (
242-
response.choices
243-
and len(response.choices) > 0
244-
and response.choices[0].delta
245-
):
233+
if response.choices and len(response.choices) > 0 and response.choices[0].delta:
246234
delta = response.choices[0].delta.content
247235
if delta:
248236
# Stream the chunk via the context manager
@@ -257,11 +245,7 @@ async def chat_completion_stream_auto_send(
257245

258246
# Update the final message content
259247
complete_message = concat_completion_chunks(chunks)
260-
if (
261-
complete_message
262-
and complete_message.choices
263-
and complete_message.choices[0].message
264-
):
248+
if complete_message and complete_message.choices and complete_message.choices[0].message:
265249
final_content = TextContent(
266250
author="agent",
267251
content=complete_message.choices[0].message.content or "",

0 commit comments

Comments
 (0)