feat: persist photos and enrich conversation history
This commit is contained in:
@@ -6,7 +6,9 @@ import asyncio
|
||||
from collections.abc import Awaitable
|
||||
from copy import deepcopy
|
||||
from dataclasses import dataclass, replace
|
||||
from time import monotonic
|
||||
from typing import Any
|
||||
from uuid import uuid4
|
||||
|
||||
from loguru import logger
|
||||
from models import AssistantConfig, RuntimeTool
|
||||
@@ -764,10 +766,46 @@ class WorkflowBrain(BaseBrain):
|
||||
|
||||
async def handler(args, _flow_manager):
|
||||
transition_id = self._state.transition_id
|
||||
invocation_id = f"tool_{uuid4().hex[:20]}"
|
||||
started_at = monotonic()
|
||||
await self._emit_trace(
|
||||
"tool_started",
|
||||
nodeId=node_id,
|
||||
invocationId=invocation_id,
|
||||
toolId=tool.id,
|
||||
toolName=tool.name,
|
||||
functionName=tool.function_name,
|
||||
toolType=tool.type,
|
||||
)
|
||||
try:
|
||||
result = await self._tools.execute(tool, dict(args or {}))
|
||||
except ToolExecutionError as exc:
|
||||
await self._emit_trace(
|
||||
"tool_failed",
|
||||
nodeId=node_id,
|
||||
invocationId=invocation_id,
|
||||
toolId=tool.id,
|
||||
toolName=tool.name,
|
||||
functionName=tool.function_name,
|
||||
toolType=tool.type,
|
||||
status="error",
|
||||
durationMs=max(0, round((monotonic() - started_at) * 1000)),
|
||||
error=str(exc)[:2048],
|
||||
)
|
||||
return {"status": "error", "message": str(exc)}
|
||||
await self._emit_trace(
|
||||
"tool_completed" if result.get("status") == "ok" else "tool_failed",
|
||||
nodeId=node_id,
|
||||
invocationId=invocation_id,
|
||||
toolId=tool.id,
|
||||
toolName=tool.name,
|
||||
functionName=tool.function_name,
|
||||
toolType=tool.type,
|
||||
status=str(result.get("status") or "unknown"),
|
||||
durationMs=max(0, round((monotonic() - started_at) * 1000)),
|
||||
updatedVariables=list(result.get("updated_variables") or []),
|
||||
resultKeys=sorted(str(name) for name in result if name != "data"),
|
||||
)
|
||||
if (
|
||||
self._state.current_node_id != node_id
|
||||
or self._state.transition_id != transition_id
|
||||
|
||||
Reference in New Issue
Block a user