# Call and stream an Agent on another AgentOS (/examples/agent-os/remote/remote-agent)



RemoteAgent presents a remote AgentOS Agent through the same asynchronous run shape used by local Agno components.

```python title="remote_agent.py"
"""
Call and stream an Agent on another AgentOS
===========================================

RemoteAgent presents a remote AgentOS Agent through the same asynchronous run
shape used by local Agno components.

Prerequisites: start `servers/agentos_server.py` and set OPENAI_API_KEY
Run: .venvs/demo/bin/python cookbook/05_agent_os/20_remote/01_remote_agent.py
Try: change either arithmetic prompt and observe the remote calculator call
"""

import asyncio

from agno.agent import RemoteAgent
from agno.run.agent import (
    RunCompletedEvent,
    RunContentEvent,
    RunErrorEvent,
    RunStartedEvent,
)

BASE_URL = "http://127.0.0.1:7780"

# ---------------------------------------------------------------------------
# Create Remote Agent
# ---------------------------------------------------------------------------

remote_assistant = RemoteAgent(
    base_url=BASE_URL,
    agent_id="assistant-agent",
)

# ---------------------------------------------------------------------------
# Run Remote Agent
# ---------------------------------------------------------------------------

async def run_remote_agent() -> None:
    """Run one complete response and one typed remote stream."""
    response = await remote_assistant.arun(
        "Use the calculator to multiply 17 by 23.",
        session_id="remote-agent-session",
    )
    print(f"Non-streaming run: {response.run_id}")
    print(response.content)

    print("\nStreaming response:")
    async for event in remote_assistant.arun(
        "Use the calculator to add 41 and 1, then explain the result.",
        session_id="remote-agent-session",
        stream=True,
        stream_events=True,
    ):
        if isinstance(event, RunStartedEvent):
            print(f"Run started: {event.run_id}")
        elif isinstance(event, RunContentEvent) and event.content is not None:
            print(event.content, end="", flush=True)
        elif isinstance(event, RunCompletedEvent):
            print(f"\nRun completed: {event.run_id}")
        elif isinstance(event, RunErrorEvent):
            raise RuntimeError(event.content or "Remote Agent run failed")

if __name__ == "__main__":
    asyncio.run(run_remote_agent())
```

## Run the Example [#run-the-example]

<Steps>
    <Step title="Set up your virtual environment">
      <CodeBlockTabs defaultValue="Mac">
        <CodeBlockTabsList>
          <CodeBlockTabsTrigger value="Mac">
            Mac
          </CodeBlockTabsTrigger>

          <CodeBlockTabsTrigger value="Windows">
            Windows
          </CodeBlockTabsTrigger>
        </CodeBlockTabsList>

        <CodeBlockTab value="Mac">
          ```bash
          uv venv --python 3.12
          source .venv/bin/activate
          ```
        </CodeBlockTab>

        <CodeBlockTab value="Windows">
          ```bash
          uv venv --python 3.12
          .venv\Scripts\activate
          ```
        </CodeBlockTab>
      </CodeBlockTabs>
    </Step>

  <Step title="Install dependencies">
    ```bash
    uv pip install -U "agno[os]" openai
    ```
  </Step>

  <Step title="Export your API keys">
    <CodeBlockTabs defaultValue="Mac/Linux">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Mac/Linux">
          Mac/Linux
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Windows">
          Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Mac/Linux">
        ```bash
        export OPENAI_API_KEY="your_openai_api_key_here"
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Windows">
        ```bash
        $Env:OPENAI_API_KEY="your_openai_api_key_here"
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </Step>

  <Step title="Clone Agno">
    Clone the pinned Agno source and run the remaining commands from its root:

    ```bash
    git clone https://github.com/agno-agi/agno.git
    cd agno
    git checkout v3.0.4
    ```
  </Step>

  <Step title="Start the remote AgentOS">
    Open another terminal in the parent directory where `.venv` and the cloned `agno` directory are siblings, then start the upstream on port 7780:

    <CodeBlockTabs defaultValue="Mac/Linux">
      <CodeBlockTabsList>
        <CodeBlockTabsTrigger value="Mac/Linux">
          Mac/Linux
        </CodeBlockTabsTrigger>

        <CodeBlockTabsTrigger value="Windows">
          Windows
        </CodeBlockTabsTrigger>
      </CodeBlockTabsList>

      <CodeBlockTab value="Mac/Linux">
        ```bash
        source .venv/bin/activate
        export OPENAI_API_KEY="your_openai_api_key_here"
        cd agno
        python cookbook/05_agent_os/20_remote/servers/agentos_server.py
        ```
      </CodeBlockTab>

      <CodeBlockTab value="Windows">
        ```powershell
        .venv\Scripts\activate
        $Env:OPENAI_API_KEY="your_openai_api_key_here"
        Set-Location agno
        python cookbook/05_agent_os/20_remote/servers/agentos_server.py
        ```
      </CodeBlockTab>
    </CodeBlockTabs>
  </Step>

  <Step title="Run the example">
    Run the example from the repository root:

    ```bash
    python cookbook/05_agent_os/20_remote/01_remote_agent.py
    ```
  </Step>
</Steps>

Full source: [cookbook/05\_agent\_os/20\_remote/01\_remote\_agent.py](https://github.com/agno-agi/agno/blob/8f36eaf2d18e91afa7b327eec66a3cd3685dcb87/cookbook/05_agent_os/20_remote/01_remote_agent.py)
