#!/usr/bin/env python3
"""{{ agent_display_name }} Agent — Generated by ABI-Core scaffolding"""

from {{ agent_file_name }} import {{ agent_class_name }}
{% if with_web_interface %}from web_interface import AgentWebInterface
{% endif %}from abi_core.agent import AbiCore
from abi_core.agent.agent_response import AgentResponse

agent = AbiCore(
{% if with_web_interface %}    web_interface_cls=AgentWebInterface,
    interface_name="{{ agent_display_name }} Web Interface",
{% endif %})

{% if tasks %}
# ── Steps — atomic DAG nodes ─────────────────────────────────────
# Each step is a deterministic unit of work.
# Add inputs via input_map and depends_on for sequencing.
{% for task in tasks %}

@agent.step(name="{{ task }}_step", input_map={"query": "$input.query"})
async def {{ task }}_step(query):
    """TODO: Implement the {{ task }} step logic.

    Args:
        query: Input query from the request.

    Returns:
        dict with the step output.
    """
    # TODO: Add your implementation here
    return {"result": None}
{% endfor %}


# ── Tasks — orchestration layer ───────────────────────────────────
# Each task composes one or more steps.
# Use agent.execute_step() to call steps, asyncio.gather() for parallel.
{% for task in tasks %}

@agent.task(name="{{ task }}", task_id="task-{{ task | replace('_', '-') }}")
async def {{ task }}(query):
    """{{ task | replace('_', ' ') | title }} — orchestrates the {{ task }}_step.

    Extend this task to:
    - Call multiple steps in sequence or parallel
    - Add branching logic
    - Stream status updates to the client
    """
    yield AgentResponse.status("Processing {{ task | replace('_', ' ') }}...")

    result = await agent.execute_step("{{ task }}_step", query=query)

    yield AgentResponse.result(result)
{% endfor %}

{% else %}
# No tasks defined. Add steps and tasks manually:
#
# @agent.step(name="my_step", input_map={"query": "$input.query"})
# async def my_step(query):
#     return {"result": "processed"}
#
# @agent.task(name="my_task", task_id="task-001")
# async def my_task(query):
#     yield AgentResponse.status("Working...")
#     result = await agent.execute_step("my_step", query=query)
#     yield AgentResponse.result(result)
{% endif %}

agent.run({{ agent_class_name }}())
