Усилить надёжность: логирование, lifespan, LRU-кэш и fail-fast семантика
Подключить loguru и заменить молчаливые except на warning/exception в step_planner, mcp_client и mcp_workflow_runner — раньше ошибки терялись в пустых дикт-возвратах.\n Перенести Phoenix tracing из module-level в FastAPI lifespan, чтобы импорт agent_os не поднимал трейсер в тестах и тулах.\n Заменить неограниченный dict _workflow_cache на OrderedDict-LRU с лимитом WORKFLOW_CACHE_MAX_SIZE (default 64) — чтобы кэш не рос бесконечно при разных scenario_id.\n Зафиксировать инвариант fail-fast: шаги, не дошедшие до исполнения из-за падения upstream, возвращаются со статусом skipped (для UI), а не queued; run помечается success только если все payload.ok.\n Добавить module docstrings во все модули src/ по STYLE_GUIDE cookbook. Запинить версии зависимостей в requirements.txt.
This commit is contained in:
@@ -1,3 +1,12 @@
|
||||
"""LLM-backed fallback planner for MCP tool arguments.
|
||||
|
||||
When a step's resolved arguments are missing required fields, this module
|
||||
calls an OpenAI-compatible chat completion to fill them from the current
|
||||
scope (``input`` + prior ``steps``). The planner is best-effort: on any
|
||||
failure it returns the base arguments unchanged so the caller's validator
|
||||
can produce a clean error.
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from copy import deepcopy
|
||||
@@ -5,6 +14,7 @@ import json
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from loguru import logger
|
||||
from openai import AsyncOpenAI
|
||||
|
||||
|
||||
@@ -121,6 +131,12 @@ async def plan_arguments(
|
||||
raw = completion.choices[0].message.content if completion.choices else ""
|
||||
planned = _extract_arguments(raw)
|
||||
except Exception:
|
||||
logger.warning(
|
||||
"Planner call failed for step={} tool={} attempt={}",
|
||||
step_name,
|
||||
tool_name,
|
||||
attempt_no,
|
||||
)
|
||||
planned = {}
|
||||
|
||||
merged = deepcopy(base_arguments)
|
||||
|
||||
Reference in New Issue
Block a user