> ## Documentation Index
> Fetch the complete documentation index at: https://agi-docs.pandas-ai.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture

> Understanding PandaAGI as a development framework for building and deploying agentic AI applications

## PandaAGI Architecture Overview

<Note>
  **PandaAGI** is a fully agentic execution ecosystem built for developers who want AI that **does** things, not just generates content. The system consists of **three core components**: the API, the SDK, and the execution environments.
</Note>

<CardGroup cols={2}>
  <Card title="Specialized Agent Orchestration" icon="robot" color="#0285c7">
    Tasks routed to dedicated [general AI agents](/concepts/agents) optimized for specific roles
  </Card>

  <Card title="Structured Parallelism" icon="diagram-project" color="#16a34a">
    Tasks broken into subtasks that execute independently then merge
  </Card>

  <Card title="Resilience and Recovery" icon="shield" color="#8b5cf6">
    Automatic retries and reassignment for robust execution
  </Card>

  <Card title="Event-Driven Communication" icon="bolt" color="#f59e0b">
    Real-time [events](/concepts/events) for monitoring and response
  </Card>
</CardGroup>

<Frame caption="PandaAGI Architecture Diagram">
  <img className="block dark:hidden" src="https://mintcdn.com/sinaptik-0f582301/txkqljXddBbQ6cuN/images/architecture.png?fit=max&auto=format&n=txkqljXddBbQ6cuN&q=85&s=8383edb7d351215bdaa854f072f34260" alt="PandaAGI Architecture Diagram - Light Mode" width="930" height="984" data-path="images/architecture.png" />

  <img className="hidden dark:block" src="https://mintcdn.com/sinaptik-0f582301/txkqljXddBbQ6cuN/images/architecture.png?fit=max&auto=format&n=txkqljXddBbQ6cuN&q=85&s=8383edb7d351215bdaa854f072f34260" alt="PandaAGI Architecture Diagram - Dark Mode" width="930" height="984" data-path="images/architecture.png" />
</Frame>

## Separation of Concerns

<CardGroup cols={3}>
  <Card title="AI Layer" icon="brain" color="#0285c7">
    Task understanding, planning, and orchestration of tool execution
  </Card>

  <Card title="Tool Layer" icon="wrench" color="#16a34a">
    Specific operations in the local environment (file operations, API calls)
  </Card>

  <Card title="Application Layer" icon="window" color="#8b5cf6">
    User experience and business logic development
  </Card>
</CardGroup>

## The PandaAGI API

<Tabs>
  <Tab title="Overview">
    <Note>
      A **bidirectional WebSocket API** built for real-time, stateful interaction with your agents.
    </Note>

    Unlike traditional REST APIs, the PandaAGI API keeps a live connection between your application and your agent—enabling:

    <CardGroup cols={2}>
      <Card title="Streaming Execution" icon="bolt" color="#0285c7">
        Real-time updates as your agent works through tasks
      </Card>

      <Card title="Dynamic State Management" icon="database" color="#16a34a">
        Persistent context and memory across interactions
      </Card>

      <Card title="Continuous Interaction" icon="arrows-rotate" color="#8b5cf6">
        Send tasks, receive results, and monitor execution in-flight
      </Card>

      <Card title="Secure Communication" icon="lock" color="#f59e0b">
        Encrypted connections with API key authentication
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Getting Started">
    <Steps>
      <Step title="Get Your API Key">
        Sign up and obtain your API key at [agi.pandas-ai.com](https://agi.pandas-ai.com)
      </Step>

      <Step title="Install the SDK">
        ```bash theme={null}
        poetry add panda_agi
        ```
      </Step>

      <Step title="Configure Your Environment">
        ```bash theme={null}
        export PANDA_AGI_KEY="your-api-key"
        ```
      </Step>
    </Steps>
  </Tab>
</Tabs>

## The PandaAGI SDK

<Tabs>
  <Tab title="Overview">
    <Note>
      We don't believe developers should spend their time wiring sockets, managing agent state, or reinventing orchestration logic. The PandaAGI SDK exists to shift that burden away from you.
    </Note>

    The SDK handles the complex infrastructure so you can focus on building powerful applications:

    * Sets up secure, persistent socket connections
    * Manages agent state across tasks
    * Tracks tools and context
    * Enables agents to reason, act, and adapt without manual glue code
  </Tab>

  <Tab title="Agent Capabilities">
    <CardGroup cols={2}>
      <Card title="Internet Access" icon="globe" color="#0285c7">
        Agents can search the web, navigate websites, and gather information from online sources
      </Card>

      <Card title="File System" icon="folder" color="#16a34a">
        Read, write, and manage files and directories for asset management
      </Card>

      <Card title="Code Execution" icon="code" color="#8b5cf6">
        Write and execute code dynamically to solve problems programmatically
      </Card>

      <Card title="Deployment" icon="rocket" color="#f59e0b">
        Deploy web servers, APIs, and other services directly from the agent
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Event System">
    <Frame caption="Real-time Event Streaming">
      ```python theme={null}
      from panda_agi import Agent, EventType, BaseHandler
      from panda_agi.client.models import BaseStreamEvent


      # Use event handler for real-time processing
      class WebAppHandler(BaseHandler):
          def process(self, event: BaseStreamEvent) -> None:
              if event.type == EventType.THINKING:
                  print(f"Agent is thinking: {event.data}")
              elif event.type == EventType.WEB_SEARCH:
                  print(f"Searching the web for: {event.data}")
              # Handle other event types...

      handlers = [WebAppHandler("WebAppBuilder")]

      agent = Agent(environment=env, event_handlers=handlers)
      response = await agent.run("Build me a simple web app")
      ```
    </Frame>

    <Note>
      All agent activities generate real-time [events](/concepts/events) that you can subscribe to for monitoring progress, collecting results, and responding to state changes.
    </Note>
  </Tab>
</Tabs>

<CardGroup cols={2}>
  <Card title="Learn more about Agents" icon="robot" href="/concepts/agents">
    Learn how agents work, their capabilities, and how to configure them for your needs
  </Card>

  <Card title="Explore Events" icon="bell" href="/concepts/events">
    Discover how to use events for real-time monitoring and response in your applications
  </Card>
</CardGroup>

The general AI agents generate real-time events in their own execution environment.

## The Execution Environments

<Tabs>
  <Tab title="Overview">
    <Note>
      [General AI agents](/concepts/agents) that reason need a place to act. The [execution environment](/concepts/environments) is that space: a clean, isolated context where agents can safely operate.
    </Note>

    <CardGroup cols={2}>
      <Card title="Isolated & Secure" icon="shield-halved" color="#0285c7">
        Each environment is ephemeral, containerized, and independent—created for a single user or session
      </Card>

      <Card title="Flexible Deployment" icon="server" color="#16a34a">
        Run on the cloud, on your own hardware, or across both
      </Card>

      <Card title="Self-Contained" icon="box" color="#8b5cf6">
        Execution is local to the agent—self-contained, inspectable, and secure
      </Card>

      <Card title="Full-Featured" icon="toolbox" color="#f59e0b">
        Write and run code, store state, interact with external systems, and build mental models
      </Card>
    </CardGroup>
  </Tab>

  <Tab title="Environment Types">
    <AccordionGroup>
      <Accordion title="Local Environment" icon="laptop-code">
        Run agents in your local filesystem with the `LocalEnv` class. Perfect for development and testing.

        ```python theme={null}
        from panda_agi import Agent
        from panda_agi.envs import LocalEnv

        # Create a local environment
        env = LocalEnv(base_path="./my_workspace")

        # Initialize agent with the environment
        agent = Agent(environment=env)
        ```
      </Accordion>

      <Accordion title="Docker Environment" icon="docker">
        Isolate agent execution in Docker containers with the `DockerEnv` class. Provides better security and reproducibility.

        ```python theme={null}
        from panda_agi import Agent
        from panda_agi.envs import DockerEnv

        # Create a Docker environment
        env = DockerEnv(workspace_path="./my_workspace")

        # Initialize agent with the environment
        agent = Agent(environment=env)
        ```
      </Accordion>
    </AccordionGroup>
  </Tab>
</Tabs>

## Getting Started with PandaAGI

<Steps>
  <Step title="Install the SDK">
    ```bash theme={null}
    # Using Poetry (recommended)
    poetry add panda_agi

    # Or with pip
    pip install panda_agi
    ```
  </Step>

  <Step title="Set up your environment">
    ```bash theme={null}
    # Set your API key
    export PANDA_AGI_KEY="your-api-key"
    ```
  </Step>

  <Step title="Create your first agent">
    ```python theme={null}
    from panda_agi import Agent
    from panda_agi.envs import LocalEnv
    from panda_agi.handlers import LogsHandler

    # Create a local environment
    env = LocalEnv(base_path="./my_workspace")

    # Initialize agent with the environment
    agent = Agent(environment=env)

    # Run the agent with event handlers
    handlers = [LogsHandler(use_colors=True, show_timestamps=True)]
    response = await agent.run("Build me a simple web app", event_handlers=handlers)
    print(f"Web app creation completed: {response.output}")
    ```
  </Step>
</Steps>

## Explore PandaAGI Components

<CardGroup cols={2}>
  <Card title="Quick Start Guide" icon="rocket" href="/quickstart" color="#0285c7">
    Get up and running with PandaAGI in minutes
  </Card>

  <Card title="Agent Concepts" icon="robot" href="/concepts/agents" color="#16a34a">
    Learn about agent capabilities, configuration, and best practices
  </Card>

  <Card title="Event System" icon="bolt" href="/concepts/events" color="#8b5cf6">
    Understand the event-driven communication system
  </Card>

  <Card title="Environments" icon="server" href="/concepts/environments" color="#f59e0b">
    Explore execution environments and their capabilities
  </Card>

  <Card title="CLI Interface" icon="terminal" href="/cli" color="#ef4444">
    Use the command-line interface for quick prototyping
  </Card>

  <Card title="Chat Interface" icon="comments" href="/chat-interface" color="#6366f1">
    Build interactive chat applications with PandaAGI
  </Card>
</CardGroup>
