ajustes de mcp
This commit is contained in:
@@ -77,7 +77,7 @@ class BaseAgent:
|
||||
|
||||
full_text = ""
|
||||
tool_calls: list[dict[str, Any]] = []
|
||||
current_tool: dict[str, Any] = {}
|
||||
current_tool: dict[str, Any] | None = None
|
||||
|
||||
async for chunk in self.model.stream(
|
||||
messages=ctx.to_messages(),
|
||||
@@ -96,7 +96,7 @@ class BaseAgent:
|
||||
session_id=session.session_id,
|
||||
)
|
||||
|
||||
if chunk.tool_name and not current_tool.get("name"):
|
||||
if chunk.tool_name and (current_tool is None or not current_tool.get("name")):
|
||||
current_tool = {
|
||||
"id": chunk.tool_call_id,
|
||||
"name": chunk.tool_name,
|
||||
@@ -108,18 +108,23 @@ class BaseAgent:
|
||||
session_id=session.session_id,
|
||||
)
|
||||
|
||||
if chunk.tool_arguments and current_tool:
|
||||
if chunk.tool_arguments and current_tool is not None and not chunk.finish_reason:
|
||||
# Accumulate partial argument chunks (NOT the final one)
|
||||
current_tool["arguments"] += chunk.tool_arguments
|
||||
|
||||
if chunk.finish_reason == "tool_use" and current_tool.get("name"):
|
||||
# Parse arguments
|
||||
if chunk.finish_reason == "tool_use" and current_tool is not None and current_tool.get("name"):
|
||||
# Final chunk carries complete arguments — use those if
|
||||
# partial accumulation is empty, otherwise use accumulated
|
||||
final_args = current_tool["arguments"] or chunk.tool_arguments or ""
|
||||
try:
|
||||
args = json.loads(current_tool["arguments"]) if current_tool["arguments"] else {}
|
||||
args = json.loads(final_args) if final_args else {}
|
||||
except json.JSONDecodeError:
|
||||
logger.warning("Failed to parse tool args: %s", final_args[:200])
|
||||
args = {}
|
||||
current_tool["parsed_arguments"] = args
|
||||
logger.debug("Tool call finalized: %s args=%s", current_tool["name"], json.dumps(args)[:200])
|
||||
tool_calls.append(current_tool)
|
||||
current_tool = {}
|
||||
current_tool = None
|
||||
|
||||
if chunk.finish_reason == "end_turn":
|
||||
break
|
||||
@@ -168,6 +173,8 @@ class BaseAgent:
|
||||
status=ToolExecutionStatus.RUNNING,
|
||||
)
|
||||
|
||||
logger.info("Tool call: %s(%s)", tool_name, json.dumps(arguments)[:200])
|
||||
|
||||
start = time.monotonic()
|
||||
try:
|
||||
if self.mcp.is_running and tool_name in self.mcp.tools:
|
||||
|
||||
Reference in New Issue
Block a user