> ## Documentation Index
> Fetch the complete documentation index at: https://phidatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Team Task Streaming Demo with AgentOS

> Expose a Team running in `tasks` mode via AgentOS.

Expose a Team running in `tasks` mode via AgentOS. You can use the AgentOS API to send requests and test task streaming.

<Warning>
  This example docstring contains a stale file path and an invalid JSON request to a removed `/v1/.../runs/stream` route. Use the generated run and streaming steps below instead.
</Warning>

```python team_tasks_streaming.py theme={null}
"""Team Task Streaming Demo with AgentOS

This example demonstrates how to expose a Team running in `tasks` mode via AgentOS.
You can use the AgentOS API to send requests and test task streaming.

Usage:
    uv run cookbook/05_agent_os/team_tasks_streaming.py

    Then you can test streaming using curl:
    curl -X POST http://0.0.0.0:7777/v1/teams/research-team/runs/stream \
         -H "Content-Type: application/json" \
         -d '{"message": "What are the key benefits of microservices architecture?"}'
"""

from agno.agent import Agent
from agno.db.postgres import PostgresDb
from agno.models.openai import OpenAIChat
from agno.os import AgentOS
from agno.team.mode import TeamMode
from agno.team.team import Team

# ---------------------------------------------------------------------------
# Create Database
# ---------------------------------------------------------------------------

db = PostgresDb(db_url="postgresql+psycopg://ai:ai@localhost:5532/ai")

# ---------------------------------------------------------------------------
# Create Members
# ---------------------------------------------------------------------------

researcher = Agent(
    name="Researcher",
    role="Researches topics and gathers information",
    model=OpenAIChat(id="gpt-5-mini"),
    db=db,
    instructions=[
        "Research the given topic thoroughly.",
        "Provide factual information.",
    ],
)

summarizer = Agent(
    name="Summarizer",
    role="Summarizes information into concise points",
    model=OpenAIChat(id="gpt-5-mini"),
    db=db,
    instructions=["Create clear, concise summaries.", "Highlight key points."],
)

# ---------------------------------------------------------------------------
# Create Team
# ---------------------------------------------------------------------------

team = Team(
    id="research-team",
    name="Research Team",
    mode=TeamMode.tasks,
    model=OpenAIChat(id="gpt-5-mini"),
    members=[researcher, summarizer],
    db=db,
    instructions=[
        "You are a research team leader. Follow these steps exactly:",
        "1. Create ALL tasks for the Researcher to gather information.",
        "2. Create ALL tasks for the Summarizer to summarize the research.",
        "3. Execute the Researcher's task.",
        "4. Execute the Summarizer's task.",
        "5. Call mark_all_complete with a final summary when all tasks are done.",
    ],
    max_iterations=3,
)

# ---------------------------------------------------------------------------
# AgentOS
# ---------------------------------------------------------------------------

agent_os = AgentOS(
    name="Team Tasks Streaming Demo",
    teams=[team],
)
app = agent_os.get_app()

# ---------------------------------------------------------------------------
# Run
# ---------------------------------------------------------------------------

if __name__ == "__main__":
    agent_os.serve(app="team_tasks_streaming:app", port=7777, reload=True)
```

## Run the Example

<Steps>
  <Snippet file="create-venv-step.mdx" />

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U "agno[os]" "psycopg[binary]" openai
    ```
  </Step>

  <Step title="Export your OpenAI API key">
    <CodeGroup>
      ```bash Mac/Linux theme={null}
      export OPENAI_API_KEY="your_openai_api_key_here"
      ```

      ```bash Windows theme={null}
      $Env:OPENAI_API_KEY="your_openai_api_key_here"
      ```
    </CodeGroup>
  </Step>

  <Snippet file="run-pgvector-step.mdx" />

  <Step title="Start AgentOS">
    Save the code above as `team_tasks_streaming.py`, then run:

    ```bash theme={null}
    python team_tasks_streaming.py
    ```

    Keep the server running while you send the streaming request.
  </Step>

  <Step title="Test task streaming">
    In a second terminal, send form fields to the v2.7.2 team run endpoint:

    ```bash theme={null}
    curl -N -X POST http://localhost:7777/teams/research-team/runs \
      -H "Accept: text/event-stream" \
      -F "message=What are the key benefits of microservices architecture?" \
      -F "stream=true"
    ```
  </Step>
</Steps>

Full source: [cookbook/05\_agent\_os/team\_tasks/team\_tasks\_streaming.py](https://github.com/agno-agi/agno/blob/main/cookbook/05_agent_os/team_tasks/team_tasks_streaming.py)
