from datetime import datetime from core_db import AuditMixin, Base, EntityMixin, VersionMixin from core_shared import JSONValue from sqlalchemy import DateTime, String, Text from sqlalchemy.dialects.sqlite import JSON from sqlalchemy.orm import Mapped, mapped_column class AgentToolInvocation(EntityMixin, AuditMixin, VersionMixin, Base): __tablename__ = "agent_tool_invocation" agent_run_id: Mapped[str] = mapped_column(String(36), index=True) agent_id: Mapped[str] = mapped_column(String(36), index=True) agent_version_id: Mapped[str] = mapped_column(String(36), index=True) tool_code: Mapped[str | None] = mapped_column(String(128), nullable=True, index=True) tool_binding_id: Mapped[str | None] = mapped_column(String(36), nullable=True, index=True) status: Mapped[str] = mapped_column(String(32), default="selected", index=True) reason: Mapped[str | None] = mapped_column(String(128), nullable=True) input_json: Mapped[dict[str, JSONValue]] = mapped_column(JSON, default=dict) output_text: Mapped[str | None] = mapped_column(Text, nullable=True) output_json: Mapped[dict[str, JSONValue] | None] = mapped_column(JSON, nullable=True) error_message: Mapped[str | None] = mapped_column(Text, nullable=True) started_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) finished_time: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)