Files
leocrm/alembic/versions/0121_agent_run_steps.py
Agent Zero c760b5961c
Check Cross-Plugin Imports / check (push) Has been cancelled
feat(F-LOOP): true ReAct loop with structured Thought/Action/Observation step tracking
- app/ai/agent_loop.py: ReActStep + ReActResult dataclasses, run_react_loop()
  with LLM→Tool→Observe loop, max_steps/timeout graceful stop, ErrorCategory
  retry (TRANSIENT→retry, PERMANENT→stop, PARTIAL→continue), cost accumulation,
  agent.step hook, on_step callback
- app/plugins/builtins/automation/models.py: AgentRunStep model
- alembic/versions/0121_agent_run_steps.py: migration for agent run steps table
- app/plugins/builtins/automation/agent_runner.py: refactored to use run_react_loop(),
  saves steps to DB, updates AgentRun with cost/status/duration
- tests/test_agent_loop.py: 11 tests (all passing, mocked, no DB/LLM needed)
- PROGRESS.md: Phase F started, F-LOOP marked done
2026-08-17 16:11:26 +02:00

52 lines
1.6 KiB
Python

"""Create automation_agent_run_steps table for ReAct loop step tracking.
Revision ID: 0121
Revises: 0120
"""
from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import JSONB, UUID as PGUUID
revision = "0121"
down_revision = "0120"
branch_labels = None
depends_on = None
def upgrade() -> None:
op.create_table(
"automation_agent_run_steps",
sa.Column("id", PGUUID(as_uuid=True), primary_key=True),
sa.Column("tenant_id", PGUUID(as_uuid=True), nullable=False, index=True),
sa.Column(
"agent_run_id",
PGUUID(as_uuid=True),
sa.ForeignKey("automation_agent_runs.id", ondelete="CASCADE"),
nullable=False,
index=True,
),
sa.Column("step_number", sa.Integer, nullable=False),
sa.Column("thought", sa.Text, nullable=True),
sa.Column("action", sa.String(255), nullable=True),
sa.Column("action_input", JSONB, nullable=True),
sa.Column("observation", sa.Text, nullable=True),
sa.Column("cost_usd", sa.Float, nullable=False, server_default="0.0"),
sa.Column(
"created_at",
sa.DateTime(timezone=True),
nullable=False,
server_default=sa.func.now(),
),
)
op.create_index(
"ix_agent_run_steps_run",
"automation_agent_run_steps",
["tenant_id", "agent_run_id"],
)
def downgrade() -> None:
op.drop_index("ix_agent_run_steps_run", table_name="automation_agent_run_steps")
op.drop_table("automation_agent_run_steps")