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

# Deploying

> Deploy your agents to production with a single command

## Overview

Deploy your agents with `ziet deploy`. Your code goes live with API endpoints, CLI access, and dashboard UI.

```bash theme={null}
ziet deploy
```

That's it. Your agent is live at `https://api.ziet.ai/agents/{agent_id}/run`

## Quick Deploy

<Steps>
  <Step title="Write your agent">
    ```python theme={null}
    # agent.py
    from ziet import Agent, Action, memory

    @Action(
        id="process_data",
        name="Process Data",
        description="Process input data"
    )
    def process_data(data: str) -> None:
        result = data.upper()
        memory.add(key="result", value=result)

    @Agent(
        id="my_agent",
        name="MyAgent",
        instructions="Process data using the process_data action",
        actions=["process_data"]
    )
    class MyAgent:
        pass
    ```
  </Step>

  <Step title="Deploy">
    ```bash theme={null}
    ziet deploy
    ```

    Output:

    ```
    🚀 Deploying to Ziet...

    ✓ Analyzing code...
    ✓ Building agent...
    ✓ Deploying my_agent...

    ✅ Deployed successfully!

    Agent: my_agent
    Endpoint: https://api.ziet.ai/agents/my_agent/run
    Dashboard: https://dashboard.ziet.ai/agents/my_agent
    ```
  </Step>

  <Step title="Test it">
    ```bash theme={null}
    ziet run my_agent --data "hello"
    ```
  </Step>
</Steps>

## Deploy Commands

### Deploy All Agents

Deploy all agents in your project:

```bash theme={null}
ziet deploy
```

### Deploy Specific Agent

Deploy only one agent:

```bash theme={null}
ziet deploy my_agent
```

### Deploy to Environment

Specify production or development:

```bash theme={null}
ziet deploy --env production
ziet deploy --env development
```

### Deploy Options

```bash theme={null}
# Dry run (validate without deploying)
ziet deploy --dry-run

# Force redeploy (bypass cache)
ziet deploy --force

# Verbose output
ziet deploy --verbose
```

## Project Structure

Recommended layout:

```
my-agent/
├── agent.py              # Agent definition
├── actions/              # Action functions (optional)
│   ├── __init__.py
│   ├── search.py
│   └── process.py
├── requirements.txt      # Python dependencies
└── .env                  # Local env vars (git-ignored)
```

Keep it simple - all you need is your Python file and `requirements.txt`.

## Configuration (Optional)

### requirements.txt

List your Python dependencies:

```txt theme={null}
requests==2.31.0
openai==1.3.0
stripe==7.0.0
```

Ziet automatically installs these when deploying.

### Environment Variables

Set secrets in the [dashboard](https://dashboard.ziet.ai/settings/environment-variables):

<Tabs>
  <Tab title="Dashboard">
    1. Go to **Settings** → **Environment Variables**
    2. Click **Add Variable**
    3. Enter key and value
    4. Click **Save**
    5. Deploy (variables are automatically available)
  </Tab>

  <Tab title="CLI">
    ```bash theme={null}
    # Set variable
    ziet env set OPENAI_API_KEY="sk-..."

    # Set multiple
    ziet env set API_KEY="key123" DATABASE_URL="postgres://..."
    ```
  </Tab>
</Tabs>

**Access in code**:

```python theme={null}
import os

api_key = os.getenv("OPENAI_API_KEY")
```

## Environments

### Development vs Production

Test in development before going to production:

```bash theme={null}
# Deploy to development
ziet deploy --env development

# Test it
ziet run my_agent --env development --data "test"

# Deploy to production
ziet deploy --env production
```

## Versioning

### Automatic Versioning

Each deployment creates a new version:

```bash theme={null}
ziet deploy

# Output: Deployed my_agent@v23
```

### Rollback

Roll back to a previous version:

```bash theme={null}
# List versions
ziet versions my_agent

# Rollback
ziet rollback my_agent --version v22
```

## Best Practices

<AccordionGroup>
  <Accordion title="Use environment variables for secrets" icon="key">
    Never hardcode API keys:

    ```python theme={null}
    # ✅ Good
    api_key = os.getenv("API_KEY")

    # ❌ Bad
    api_key = "sk-12345..."
    ```
  </Accordion>

  <Accordion title="Test locally first" icon="flask">
    ```bash theme={null}
    # Test locally
    ziet run --local --agent my_agent

    # Then deploy
    ziet deploy
    ```
  </Accordion>

  <Accordion title="Use separate environments" icon="layer-group">
    ```bash theme={null}
    # Test in dev
    ziet deploy --env development

    # Promote to production
    ziet deploy --env production
    ```
  </Accordion>

  <Accordion title="Keep dependencies minimal" icon="box">
    Only include what you need in `requirements.txt`:

    ```txt theme={null}
    # Only list packages you actually import
    openai==1.3.0
    stripe==7.0.0
    ```
  </Accordion>
</AccordionGroup>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Deployment fails">
    **Solutions**:

    ```bash theme={null}
    # Check for syntax errors
    python agent.py

    # Validate deployment
    ziet deploy --dry-run

    # Check logs
    ziet deploy --verbose
    ```
  </Accordion>

  <Accordion title="Missing dependencies">
    **Solution**: Add to `requirements.txt`

    ```txt theme={null}
    # requirements.txt
    requests==2.31.0
    openai==1.3.0
    ```

    Then redeploy:

    ```bash theme={null}
    ziet deploy --force
    ```
  </Accordion>

  <Accordion title="Environment variables not working">
    **Solutions**:

    1. Check dashboard: **Settings** → **Environment Variables**
    2. Verify exact name:

    ```python theme={null}
    key = os.getenv("API_KEY")  # Must match dashboard
    ```

    3. Redeploy:

    ```bash theme={null}
    ziet deploy --force
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={2}>
  <Card title="Invoking" icon="play" href="/deployment/invoking">
    Run your deployed agents
  </Card>

  <Card title="Monitoring" icon="chart-line" href="/deployment/monitoring">
    View logs and metrics
  </Card>

  <Card title="API Reference" icon="code" href="/api-reference/introduction">
    REST API documentation
  </Card>

  <Card title="Agents" icon="robot" href="/core/agents">
    Learn more about agents
  </Card>
</CardGroup>
