# Main entry for agent workflow
from evenage import Workflow

# Coordinator-based workflow
coordinator_workflow = Workflow(
    name="coordinated_research_pipeline",
    description="Coordinator-based workflow with dynamic task delegation",
    mode="coordinator"  # Special mode
)
coordinator_workflow.add_coordinator(coordinator)
coordinator_workflow.add_worker(researcher)
coordinator_workflow.add_worker(analyst)
coordinator_workflow.add_worker(writer)
coordinator_workflow.configure(
    trace_db="postgresql://evenage:evenage@postgres:5432/evenage",
    artifact_storage="minio://minioadmin:minioadmin123@minio:9000/artifacts",
    dashboard_port=5173,
    queue_backend="redis",
    queue_uri=os.getenv("QUEUE_URI", "redis://localhost:6379/0"),
    coordinator_settings={
        "max_delegation_depth": 3,
        "wait_for_completion": True,
        "parallel_delegations": True
    }
)

# Sequential workflow
sequential_workflow = Workflow(
    name="sequential_research_pipeline",
    description="Sequential workflow for research, analysis, and writing"
)
sequential_workflow.add_node(researcher, next="analyst")
sequential_workflow.add_node(analyst, next="writer")
sequential_workflow.add_node(writer)
sequential_workflow.configure(
    trace_db="postgresql://evenage:evenage@postgres:5432/evenage",
    artifact_storage="minio://minioadmin:minioadmin123@minio:9000/artifacts",
    dashboard_port=5173
)
#!/usr/bin/env python
from __future__ import annotations

import asyncio
import json
import sys
from typing import Any, Dict

from evenage.core import AgentRunner, EvenAgeConfig


def run() -> None:
    inputs: Dict[str, Any] = {}
    if len(sys.argv) > 2:
        try:
            inputs = json.loads(sys.argv[2])
        except Exception:
            inputs = {}
    runner = AgentRunner(env_config=EvenAgeConfig())
    result = asyncio.run(runner.run(inputs, agent_name="{{ default_agent | snake_case }}"))
    print("\n\n=== FINAL OUTPUT ===\n")
    try:
        print(json.dumps(result, indent=2, ensure_ascii=False))
    except Exception:
        print(result)


def replay() -> None:
    if len(sys.argv) < 3:
        print("Usage: python main.py replay <job_id>")
        sys.exit(1)
    runner = AgentRunner(env_config=EvenAgeConfig())
    result = runner.replay(sys.argv[2], reexecute=False)
    print(json.dumps(result, indent=2, ensure_ascii=False))


if __name__ == "__main__":
    command = sys.argv[1] if len(sys.argv) > 1 else "run"
    if command == "run":
        run()
    elif command == "replay":
        replay()
    else:
        print(f"Unknown command: {command}")
