Spaces:
Runtime error
Runtime error
File size: 2,049 Bytes
1ffd0a4 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | """
AgentResult β the canonical contract every agent in the CIRO pipeline returns.
Why this exists
---------------
The pipeline (detection β analysis β planning β simulation) chains heterogeneous
agents together. Each stage feeds the next, and the agent-trace UI renders every
step uniformly. To keep that working, every agent β regardless of what it does β
must produce the same outer shape. That shape is `AgentResult`.
`output` is intentionally a free-form dict so individual agents can return their
own domain payload (detection verdict, risk tier, action plan, etc.) without
having to grow this base schema each time a new agent ships.
"""
from datetime import datetime, timezone
from typing import Any
from pydantic import BaseModel, Field
class AgentResult(BaseModel):
"""Uniform output every CIRO agent must produce.
Attributes:
agent_name: Stable identifier of the agent that produced this result
(e.g. "detection_agent"). Used in trace logs + downstream routing.
success: True iff the agent completed without raising. A `success=False`
result still carries `reasoning` describing why it failed so the
pipeline can short-circuit gracefully.
output: Free-form domain payload produced by the agent. Each agent
documents its own output keys in its own module.
reasoning: Plain-language explanation of how the agent reached its
decision. Surfaced directly in the in-app agent-trace timeline.
confidence: Self-reported confidence in `output`, clamped to [0, 1].
Downstream stages (risk tiering, crowd verification) use this.
timestamp: When the result was finalized (UTC). Used for ordering
steps in the trace log.
"""
agent_name: str
success: bool
output: dict[str, Any] = Field(default_factory=dict)
reasoning: str = ""
confidence: float = Field(default=0.0, ge=0.0, le=1.0)
timestamp: datetime = Field(default_factory=lambda: datetime.now(timezone.utc))
|