Coverage for /home/admin/Documents/AI/applications/lexigram-dev/lexigram/experimental/ai/lexigram-ai-agents/src/lexigram/ai/agents/types.py: 97%
37 statements
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
« prev ^ index » next coverage.py v7.15.4, created at 2026-08-25 07:19 +0800
1"""Agent types — concrete implementations for agent execution.
3Defines ToolExecutionRecord and ReasoningStep (concrete agent data structures).
4AgentResponse is re-exported from contracts as it's used in protocol signatures.
5"""
7from __future__ import annotations
9from dataclasses import dataclass, field
10from datetime import UTC, datetime
11from typing import Any
13from lexigram.contracts.ai.agents import AgentResponse
16@dataclass
17class ToolExecutionRecord:
18 """Record of a single tool invocation during agent execution.
20 Captures the tool name, arguments, result (or error), and timing
21 for observability and debugging.
22 """
24 tool_name: str
25 """Name of the tool that was called."""
27 arguments: dict[str, Any] = field(default_factory=dict)
28 """Arguments passed to the tool."""
30 result: Any = None
31 """Return value from the tool (None if error)."""
33 error: str | None = None
34 """Error message if the tool call failed."""
36 duration_ms: float = 0.0
37 """Execution time in milliseconds."""
39 timestamp: datetime = field(default_factory=lambda: datetime.now(UTC))
40 """When the tool was called."""
42 @property
43 def succeeded(self) -> bool:
44 """Whether the tool call completed without error."""
45 return self.error is None
48@dataclass
49class ReasoningStep:
50 """A single step in the agent's reasoning process.
52 Each step captures the agent's thought, the action it decided
53 to take (if any), the tool call (if any), and the observation
54 from the tool result or LLM response.
55 """
57 step_number: int
58 """Sequential step number (1-based)."""
60 thought: str = ""
61 """The agent's reasoning at this step."""
63 action: str | None = None
64 """The action decided (tool name or 'respond')."""
66 tool_call: ToolExecutionRecord | None = None
67 """Tool call details (if action was a tool call)."""
69 observation: str | None = None
70 """Result of the action — tool output or final response."""
72 timestamp: datetime = field(default_factory=lambda: datetime.now(UTC))
73 """When this step occurred."""
76__all__ = [
77 "AgentResponse",
78 "ReasoningStep",
79 "ToolExecutionRecord",
80]