mirror of
https://github.com/eigent-ai/eigent.git
synced 2026-07-10 01:38:37 +00:00
Merge c24b097631 into 97d7554438
This commit is contained in:
commit
8dda62d1a6
1 changed files with 45 additions and 0 deletions
|
|
@ -32,6 +32,42 @@ from app.service.task import ActionCreateAgentData, Agents, get_task_lock
|
|||
from app.utils.event_loop_utils import _schedule_async_task
|
||||
|
||||
|
||||
def _sanitize_tool_schema(obj):
|
||||
"""Recursively fix tool JSON schemas for strict providers (e.g. Groq)."""
|
||||
if isinstance(obj, list):
|
||||
for item in obj:
|
||||
_sanitize_tool_schema(item)
|
||||
return
|
||||
if not isinstance(obj, dict):
|
||||
return
|
||||
# force additionalProperties to false on objects
|
||||
if obj.get("type") == "object":
|
||||
obj["additionalProperties"] = False
|
||||
# collapse integer/number overlap in anyOf/oneOf
|
||||
for union_key in ("anyOf", "oneOf"):
|
||||
union = obj.get(union_key)
|
||||
if isinstance(union, list):
|
||||
types_in_union = [
|
||||
item.get("type")
|
||||
for item in union
|
||||
if isinstance(item, dict) and "type" in item
|
||||
]
|
||||
if "integer" in types_in_union and "number" in types_in_union:
|
||||
obj[union_key] = [
|
||||
item
|
||||
for item in union
|
||||
if not (
|
||||
isinstance(item, dict)
|
||||
and item.get("type") == "integer"
|
||||
)
|
||||
]
|
||||
# Recurse
|
||||
for key, value in list(obj.items()):
|
||||
if key == "additionalProperties" and value is not False:
|
||||
continue
|
||||
_sanitize_tool_schema(value)
|
||||
|
||||
|
||||
def agent_model(
|
||||
agent_name: str,
|
||||
system_message: str | BaseMessage,
|
||||
|
|
@ -192,6 +228,15 @@ def agent_model(
|
|||
**init_params,
|
||||
)
|
||||
|
||||
# Fix tool schemas for strict providers (e.g. Groq) that require
|
||||
# additionalProperties: false and reject integer/number overlap.
|
||||
if tools:
|
||||
for tool in tools:
|
||||
if isinstance(tool, FunctionTool) and hasattr(
|
||||
tool, "openai_tool_schema"
|
||||
):
|
||||
_sanitize_tool_schema(tool.openai_tool_schema)
|
||||
|
||||
return ListenChatAgent(
|
||||
options.project_id,
|
||||
agent_name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue