Skip to content

Commit c0a6786

Browse files
authored
chore: Code tidy for Anthropic and Google Gemini client classes (#2311)
* Code tidy for Anthropic and Google Gemini * Fix test bug
1 parent bb2f81c commit c0a6786

File tree

4 files changed

+7
-21
lines changed

4 files changed

+7
-21
lines changed

autogen/oai/anthropic.py

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,7 @@ def supports_native_structured_outputs(model: str) -> bool:
186186
return True
187187

188188
# Support future Opus 4.x versions
189-
if model.startswith("claude-opus-4"):
190-
return True
191-
192-
return False
189+
return bool(model.startswith("claude-opus-4"))
193190

194191

195192
def has_beta_messages_api() -> bool:
@@ -265,9 +262,7 @@ def _is_text_block(content: Any) -> bool:
265262
"""
266263
if type(content) == TextBlock:
267264
return True
268-
if BETA_BLOCKS_AVAILABLE and type(content) == BetaTextBlock:
269-
return True
270-
return False
265+
return BETA_BLOCKS_AVAILABLE and type(content) == BetaTextBlock
271266

272267

273268
def _is_tool_use_block(content: Any) -> bool:
@@ -288,10 +283,7 @@ def _is_tool_use_block(content: Any) -> bool:
288283
return True
289284

290285
# Fallback: check by name if type comparison fails
291-
if content_type_name in ("ToolUseBlock", "BetaToolUseBlock"):
292-
return True
293-
294-
return False
286+
return content_type_name in ("ToolUseBlock", "BetaToolUseBlock")
295287

296288

297289
def _is_thinking_block(content: Any) -> bool:
@@ -310,10 +302,7 @@ def _is_thinking_block(content: Any) -> bool:
310302
return True
311303

312304
# Fallback: check by name if type comparison fails
313-
if content_type_name == "ThinkingBlock":
314-
return True
315-
316-
return False
305+
return content_type_name == "ThinkingBlock"
317306

318307

319308
def transform_schema_for_anthropic(schema: dict[str, Any]) -> dict[str, Any]:

test/agentchat/test_multimodal_integration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -753,7 +753,7 @@ def test_run_group_chat_multimodal(credentials_gpt_4o_mini: Credentials) -> None
753753

754754
# Test that response objects are properly configured (if agents attribute exists)
755755
if hasattr(response2, "agents"):
756-
assert response2.agents == [], "Initial agents list should be empty (gets populated later)"
756+
assert len(response2.agents) > 0, "Agents list should be populated"
757757

758758
# Wait for processing
759759
time.sleep(2)

test/oai/test_anthropic.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,10 +1609,7 @@ class MathResult(BaseModel):
16091609
content = final_response.choices[0].message.content
16101610

16111611
# Parse and validate structured output
1612-
if isinstance(content, str):
1613-
result = MathResult.model_validate_json(content)
1614-
else:
1615-
result = MathResult.model_validate(content)
1612+
result = MathResult.model_validate_json(content) if isinstance(content, str) else MathResult.model_validate(content)
16161613

16171614
# Verify structured output has required fields
16181615
assert result.steps, "Should have steps"

test/oai/test_gemini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1228,7 +1228,7 @@ def test_thought_signature_retained_across_calls(self, mock_calculate_cost, mock
12281228
]
12291229

12301230
# Second create call - thought_signature should still be available
1231-
response2 = gemini_client.create({
1231+
gemini_client.create({
12321232
"model": "gemini-3-flash",
12331233
"messages": messages,
12341234
"tools": [

0 commit comments

Comments
 (0)