Skip to content

Commit 7707e87

Browse files
committed
fix: Resolve runtime errors in agent execution
- Rename Tool.schema to Tool.definition to avoid shadowing BaseModel attribute - Use getattr for llm.model and llm.temperature to handle ChatOpenAI which uses model_name
1 parent e97da35 commit 7707e87

File tree

4 files changed

+10
-9
lines changed

4 files changed

+10
-9
lines changed

redis_sre_agent/agent/langgraph_agent.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,9 @@ def _messages_cache_key(self, messages: List[BaseMessage]) -> str:
369369
async def _ainvoke_memo(self, tag: str, llm: Any, messages: List[BaseMessage]):
370370
if not self._run_cache_active:
371371
return await llm.ainvoke(messages)
372-
model = llm.model
373-
temperature = llm.temperature
372+
# LLM objects use different attribute names: model, model_name, or _model
373+
model = getattr(llm, "model", None) or getattr(llm, "model_name", None) or "unknown"
374+
temperature = getattr(llm, "temperature", 0.0)
374375
key = f"{tag}|{model}|{temperature}|{self._messages_cache_key(messages)}"
375376
if key in self._llm_cache:
376377
return self._llm_cache[key]

redis_sre_agent/tools/manager.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def get_tools(self) -> List[ToolDefinition]:
268268
Returns:
269269
List of ToolDefinition objects for LLM binding
270270
"""
271-
return [t.schema for t in self._tools]
271+
return [t.definition for t in self._tools]
272272

273273
def get_tools_by_provider_names(self, provider_names: List[str]) -> List[ToolDefinition]:
274274
"""Return tools belonging to providers with given provider_name values.
@@ -289,7 +289,7 @@ def get_tools_by_provider_names(self, provider_names: List[str]) -> List[ToolDef
289289
provider = self._routing_table.get(tool.metadata.name)
290290
pname = provider.provider_name if provider else None
291291
if isinstance(pname, str) and pname.lower() in wanted:
292-
results.append(tool.schema)
292+
results.append(tool.definition)
293293
return results
294294
except Exception:
295295
# Be conservative; if anything goes wrong, return no tools
@@ -362,7 +362,7 @@ def _filter_tools_by_providers(self, providers: List["ToolProvider"]) -> List[To
362362
p = self._routing_table.get(tool.metadata.name)
363363
if not p or id(p) not in provider_ids:
364364
continue
365-
results.append(tool.schema)
365+
results.append(tool.definition)
366366
return results
367367
except Exception:
368368
return []

redis_sre_agent/tools/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,19 @@ class ToolMetadata(BaseModel):
3232

3333

3434
class Tool(BaseModel):
35-
"""Concrete tool object combining schema, metadata, and executor.
35+
"""Concrete tool object combining definition, metadata, and executor.
3636
3737
Attributes:
3838
metadata: :class:`ToolMetadata` describing the tool for routing.
39-
schema: The :class:`ToolDefinition` shown to the LLM.
39+
definition: The :class:`ToolDefinition` shown to the LLM.
4040
invoke: Async callable taking a single ``Dict[str, Any]`` of arguments
4141
and returning the tool result.
4242
"""
4343

4444
model_config = ConfigDict(arbitrary_types_allowed=True)
4545

4646
metadata: ToolMetadata
47-
schema: "ToolDefinition"
47+
definition: "ToolDefinition"
4848
invoke: Callable[[Dict[str, Any]], Awaitable[Any]]
4949

5050

redis_sre_agent/tools/protocols.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ def tools(self) -> List["Tool"]:
385385
async def _invoke(args: Dict[str, Any], _method=method) -> Any:
386386
return await _method(**(args or {}))
387387

388-
tools.append(Tool(metadata=meta, schema=schema, invoke=_invoke))
388+
tools.append(Tool(metadata=meta, definition=schema, invoke=_invoke))
389389
return tools
390390

391391
def get_status_update(self, tool_name: str, args: Dict[str, Any]) -> Optional[str]:

0 commit comments

Comments
 (0)