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

# Overview

> Turn solutions into running software

## Overview

After `evolve()` generates a solution, `deploy()` turns it into running software. The deployment pipeline handles adaptation, strategy selection, and execution.

## Deployment Flow

```mermaid theme={null}
flowchart LR
    SOL["SolutionResult"] --> SEL["Selector"]
    SEL --> ADAPT["Adapter"]
    ADAPT --> RUN["Runner"]
    RUN --> SOFT["Software"]
```

1. **Selector**: Analyzes code and chooses deployment strategy
2. **Adapter**: Modifies code for the chosen strategy
3. **Runner**: Executes the adapted code
4. **Software**: Unified interface for running and managing

## Quick Start

```python theme={null}
from kapso.kapso import Kapso, DeployStrategy

kapso = Kapso()
solution = kapso.evolve(goal="Build a classifier")

# Deploy with explicit strategy
deployed_program = kapso.deploy(solution, strategy=DeployStrategy.LOCAL)

# Run inference
result = deployed_program.run({"data_path": "./test.csv"})
print(result)  # {"status": "success", "output": ...}

# Lifecycle management
deployed_program.stop()
deployed_program.start()
deployed_program.stop()
```

## Deployment Strategies

| Strategy    | Description                  | Best For                   |
| ----------- | ---------------------------- | -------------------------- |
| `AUTO`      | System chooses best strategy | Default                    |
| `LOCAL`     | Run as local Python process  | Development, testing       |
| `DOCKER`    | Run in Docker container      | Isolation, reproducibility |
| `MODAL`     | Deploy to Modal.com          | Serverless, GPU            |
| `BENTOML`   | Deploy with BentoML          | Production ML              |
| `LANGGRAPH` | Deploy as LangGraph agent    | Agent workflows            |

## DeployStrategy Enum

```python theme={null}
from kapso.deployment import DeployStrategy

DeployStrategy.AUTO      # System selects
DeployStrategy.LOCAL     # Local process
DeployStrategy.DOCKER    # Docker container
DeployStrategy.MODAL     # Modal.com
DeployStrategy.BENTOML   # BentoML
DeployStrategy.LANGGRAPH # LangGraph
```

## Software Interface

All deployments return a `Software` instance with a unified interface:

```python theme={null}
class Software:
    def run(self, inputs: Dict) -> Dict:
        """Execute with input data."""
        # Returns: {"status": "success", "output": ...}
        # Or: {"status": "error", "error": ...}

    def stop(self) -> None:
        """Stop and cleanup resources."""

    def start(self) -> None:
        """Restart a stopped deployment."""

    def is_healthy(self) -> bool:
        """Check if service is running."""

    def logs(self) -> str:
        """Get execution logs."""
```

## Response Format

All `run()` calls return a consistent format:

```python theme={null}
# Success
{"status": "success", "output": <result>}

# Error
{"status": "error", "error": <message>}
```

## Configuration

```python theme={null}
from kapso.deployment import DeployConfig

config = DeployConfig(
    solution=solution,
    env_vars={"API_KEY": "..."},
    coding_agent="claude_code",
)

deployed_program = DeploymentFactory.create(DeployStrategy.LOCAL, config)
```

## Deployment Info

Get details about the deployment:

```python theme={null}
# Get deployment metadata
info = deployed_program.get_deployment_info()
print(info)
# {
#     "strategy": "local",
#     "provider": None,
#     "endpoint": None,
#     "adapted_path": "/path/to/adapted",
#     "adapted_files": ["main.py", "run.py"],
#     "resources": {}
# }

# Individual accessors
deployed_program.get_strategy()      # "local"
deployed_program.get_adapted_path()  # Path to adapted code
deployed_program.get_endpoint()      # HTTP endpoint (if applicable)
```

## Lifecycle Management

```python theme={null}
deployed_program = kapso.deploy(solution, strategy=DeployStrategy.LOCAL)

# Initial run
result = deployed_program.run({"data": "..."})

# Check health
if deployed_program.is_healthy():
    print("Service is running")

# Stop (cleanup resources)
deployed_program.stop()

# Restart
deployed_program.start()

# Run again
result = deployed_program.run({"data": "..."})

# Final cleanup
deployed_program.stop()
```

## Error Handling

```python theme={null}
result = deployed_program.run({"data": "..."})

if result["status"] == "error":
    print(f"Error: {result['error']}")
    print(f"Logs: {deployed_program.logs()}")
```

## Next Steps

<CardGroup cols={2}>
  <Card title="Strategies" icon="layer-group" href="/docs/deployment/strategies">
    Details on each deployment strategy
  </Card>

  <Card title="Adding Strategies" icon="plus" href="/docs/deployment/adding-strategies">
    Create custom deployment strategies
  </Card>
</CardGroup>
