Skip to content

Commit 49a2c2f

Browse files
committed
fix(foundry_agent): omit temperature for gpt-5/o-series models
Reasoning models (gpt-5*, o1, o3, o4) reject the temperature parameter with a 400 error. Passing temperature=None is also rejected because it serializes as null. Build a kwargs dict and spread into ChatAgent so temperature is fully omitted for these models, while gpt-4* models still get temperature=0.1.
1 parent c58c022 commit 49a2c2f

1 file changed

Lines changed: 18 additions & 6 deletions

File tree

src/backend/v4/magentic_agents/foundry_agent.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -225,12 +225,24 @@ async def _create_azure_search_enabled_client(self, chatClient=None) -> Optional
225225
# -------------------------
226226
async def _after_open(self) -> None:
227227
"""Initialize ChatAgent after connections are established."""
228-
if self.use_reasoning:
229-
self.logger.info("Initializing agent in Reasoning mode.")
230-
temp = None
228+
# Reasoning / GPT-5 / o-series models reject the `temperature` parameter.
229+
# Build kwargs so we can OMIT temperature entirely (passing None is also rejected).
230+
model_lc = (self.model_deployment_name or "").lower()
231+
unsupports_temperature = (
232+
model_lc.startswith("gpt-5")
233+
or model_lc.startswith("o1")
234+
or model_lc.startswith("o3")
235+
or model_lc.startswith("o4")
236+
)
237+
if self.use_reasoning or unsupports_temperature:
238+
self.logger.info(
239+
"Initializing agent in Reasoning mode (temperature disabled for model '%s').",
240+
self.model_deployment_name,
241+
)
242+
temp_kwargs: dict = {}
231243
else:
232244
self.logger.info("Initializing agent in Foundry mode.")
233-
temp = 0.1
245+
temp_kwargs = {"temperature": 0.1}
234246

235247
try:
236248
chatClient = await self.get_database_team_agent()
@@ -254,8 +266,8 @@ async def _after_open(self) -> None:
254266
name=self.agent_name,
255267
description=self.agent_description,
256268
tool_choice="required", # Force usage
257-
temperature=temp,
258269
model_id=self.model_deployment_name,
270+
**temp_kwargs,
259271
)
260272
else:
261273
# use MCP path
@@ -269,8 +281,8 @@ async def _after_open(self) -> None:
269281
description=self.agent_description,
270282
tools=tools if tools else None,
271283
tool_choice="auto" if tools else "none",
272-
temperature=temp,
273284
model_id=self.model_deployment_name,
285+
**temp_kwargs,
274286
)
275287
self.logger.info("Initialized ChatAgent '%s'", self.agent_name)
276288

0 commit comments

Comments
 (0)