"""Agents-as-Tools example: project managers for NY and London.

Parent agent ("PMO-orchestrator") calls two child agents
("NY-Project-Manager" and "London-Project-Manager") as tools. Each child uses
the ``time`` MCP server for local time and the ``fetch`` MCP server for a short
news-based update on the given topics.

Defaults: clones fork parent history (no merge-back), no timeout, no parallel cap,
and collapses progress display after the first 20 instances.
To change behavior, pass decorator args such as
`history_mode=HistoryMode.FORK_AND_MERGE`, `child_timeout_sec=600`,
`max_parallel=8`, `max_display_instances=10`
(HistoryMode import: fast_agent.agents.workflow.agents_as_tools_agent).
"""

import asyncio

from fast_agent import FastAgent

# Create the application
fast = FastAgent("Agents-as-Tools demo")


@fast.agent(
    name="NY-Project-Manager",
    instruction=(
        "You are a New York project manager. For each given topic, get the "
        "current local time in New York and a brief, project-relevant news "
        "summary using the 'time' and 'fetch' MCP servers. If a source returns "
        "HTTP 403 or is blocked by robots.txt, try up to five alternative "
        "public sources before giving up and clearly state any remaining "
        "access limits. Hint: Fast-Agent site: https://fast-agent.ai"
    ),
    servers=[
        "time",
        "fetch",
    ],  # MCP servers 'time' and 'fetch' configured in fastagent.config.yaml
)
@fast.agent(
    name="London-Project-Manager",
    instruction=(
        "You are a London project manager. For each given topic, get the "
        "current local time in London and a brief, project-relevant news "
        "summary using the 'time' and 'fetch' MCP servers. If a source returns "
        "HTTP 403 or is blocked by robots.txt, try up to five alternative "
        "public sources before giving up and clearly state any remaining "
        "access limits. Hint: BBC: https://www.bbc.com/ and FT: https://www.ft.com/"
    ),
    servers=["time", "fetch"],
)
@fast.agent(
    name="PMO-orchestrator",
    instruction=(
        "Get project updates from the New York and London project managers. "
        "Ask NY-Project-Manager three times about different projects: Anthropic, "
        "evalstate/fast-agent, and OpenAI, and London-Project-Manager for economics review. "
        "Return a brief, concise combined summary with clear city/time/topic labels."
    ),
    default=True,
    agents=[
        "NY-Project-Manager",
        "London-Project-Manager",
    ],  # children are exposed as tools: agent__NY-Project-Manager, agent__London-Project-Manager
    # optional: history_mode="fork_and_merge", child_timeout_sec=600, max_parallel=8, max_display_instances=10
)
async def main() -> None:
    async with fast.run() as agent:
        result = await agent("pls send me daily review.")
        print(result)


if __name__ == "__main__":
    asyncio.run(main())
