<p align="center">
  <h1 align="center">Alive</h1>
  <p align="center"><strong>The AI agent that builds itself. Then talks to other agents.</strong></p>
  <p align="center">
    <a href="https://pypi.org/project/alive-agent/"><img src="https://img.shields.io/pypi/v/alive-agent?style=flat-square" alt="PyPI"></a>
    <a href="https://github.com/darshanahirrao/Alive/blob/main/LICENSE"><img src="https://img.shields.io/github/license/darshanahirrao/Alive?style=flat-square" alt="License"></a>
    <a href="https://www.python.org/downloads/"><img src="https://img.shields.io/badge/python-3.11+-blue?style=flat-square" alt="Python"></a>
  </p>
</p>

---

Alive is a self-evolving AI agent. When it can't do something, it writes the code, tests it in a sandbox, and permanently learns the new ability. Every user's Alive grows differently.

But that's only half the story.

Alive speaks **ALP** (Agent Language Protocol) — an open protocol for agent-to-agent communication. Two Alive instances on the same network discover each other automatically, browse each other's skills, and exchange capabilities. **Skills mutate during transfer**, adapting to each agent's unique environment. A skill that started as a price checker on one machine might arrive on yours with Telegram alerts and local timezone support already wired in.

This is the Internet of Agents. And the protocol is open.

## Quick Start

```bash
pip install alive-agent
alive init
alive run "generate a random password with 20 characters"
```

That last command will: plan the approach, build a `generate_random_password` skill, test it in a sandbox, and return the result. The skill is now permanently installed. Next time, it runs instantly.

## The Demo That Matters

**Terminal 1:**
```bash
alive network alias darsh
alive listen --port 8484
```

**Terminal 2:**
```bash
alive network alias friend
alive listen --port 8585
alive network browse @darsh        # see darsh's skills
alive network pull web_fetch --from @darsh
```

The skill transfers. It mutates. It adapts. It's tested. It's installed. Generation increments. Lineage tracked. Two agents, evolving together.

## How It Works

```
You: "monitor Bitcoin price every 30 minutes, alert me on Telegram if it drops below 60k"

Alive:
  1. Plans: NEW_SKILL (bitcoin_checker) -> SCHEDULE (every 30m, notify telegram)
  2. Builds the skill (two implementations compete in Battle Mode)
  3. Tests both in sandbox, picks the faster correct one
  4. Saves permanently to ~/.alive/skills/bitcoin_checker/
  5. Schedules it with the daemon
  6. Wires up Telegram alerts
  Done. Running. Forever.
```

Every skill is a plain Python file with a `run(input_data: dict) -> dict` interface. No framework lock-in. No magic. Just code you can read, edit, and share.

## Features

### Self-Evolution Engine
- **Skill Builder** with Battle Mode: two implementations compete, faster correct one wins
- **Planner** decomposes requests into typed steps (EXISTING_SKILL, NEW_SKILL, LLM_ONLY, SCHEDULE)
- **Composer** executes plans step-by-step with error recovery
- **Skill Evolution**: improve existing skills based on execution statistics
- **Skill Teaching**: import any Python script as a skill (`alive teach script.py`)

### ALP Network (Agent Language Protocol)
- **UDP broadcast discovery** on port 51966 — zero config, automatic
- **Skill exchange** with security scanning and user approval
- **Mutation on transfer**: LLM adapts skills to receiver's environment
- **Lineage tracking**: generation counter + full agent chain
- **Conversation log**: human-readable record of all network activity
- **Manual connect** for cross-network peers (`alive network connect ip:port`)

### 5 Composable Integrations
- **Web Search**: DuckDuckGo (zero config), Tavily, SearXNG
- **Telegram**: alert mode + full chat bot with daemon
- **Scheduler**: interval/daily/cron with background daemon
- **Browser**: Playwright-based scraping, screenshots, form filling
- **Webhooks**: Slack, Discord, generic endpoints

### Knowledge & Memory
- **Persistent memory**: per-skill SQLite key-value store
- **Skill graph**: visualize relationships between skills (chains, co-usage, co-creation)
- **Dream log**: self-reflection on capabilities and gaps
- **Self-model**: domain classification, confidence tracking, growth timeline
- **Shell analysis**: suggest skills from your command history

### Sharing & Collaboration
- **Export/import** skills as tar.gz archives
- **GitHub Gist** publishing and importing
- **Skill chaining**: compose multiple skills into named pipelines

### Multi-Provider LLM Support
- Claude, OpenAI, DeepSeek, Ollama
- Auto-detects from API keys, configurable via `alive config`
- Falls back to Ollama (free, local) if no API key set

## ALP: The Open Protocol

ALP is bigger than Alive. It's a protocol specification that any agent can implement.

The core idea: agents should be able to find each other and share capabilities without a central authority. No app store. No API gateway. No permission required.

- **[Protocol Specification](docs/ALP_SPEC.md)** — the full technical spec
- **[Manifesto](docs/MANIFESTO.md)** — why we're building this

Implementing ALP in your agent? Open an issue with the `alp-implementation` label. We'll link your project.

## CLI Reference

Alive has 45+ commands. Here are the ones you'll use most:

```bash
# Core
alive run "your request"          # Process any request
alive build "description"         # Build a specific skill
alive skills                      # List installed skills
alive run my-pipeline             # Run a skill chain

# Network (ALP)
alive listen [--port 8484]        # Join the agent network
alive network peers               # List discovered peers
alive network browse [@alias]     # Browse a peer's skills
alive network pull <skill>        # Pull and adapt a skill
alive network log [-f]            # View network activity

# Integrations
alive search "query"              # Web search
alive schedule "task" --every 30m # Schedule recurring task
alive daemon start                # Start scheduler daemon
alive setup telegram              # Configure Telegram alerts
alive screenshot <url>            # Take webpage screenshot

# Management
alive config --provider claude    # Set LLM provider
alive teach script.py             # Import Python script as skill
alive evolve <skill>              # Improve a skill with AI
alive graph                       # Visualize skill relationships
alive dream                       # AI self-reflection
alive status                      # Show capabilities overview
```

## Installation

**From PyPI:**
```bash
pip install alive-agent
```

**From source:**
```bash
git clone https://github.com/darshanahirrao/Alive.git
cd Alive
pip install -e ".[dev]"
```

**Optional extras:**
```bash
pip install alive-agent[telegram]   # Telegram bot support
pip install alive-agent[browser]    # Playwright browser automation
pip install alive-agent[all]        # Everything
```

## Configuration

```bash
# Set your LLM provider
alive config --provider claude --claude-key sk-ant-...
alive config --provider openai --openai-key sk-...
alive config --provider ollama  # Free, no API key needed

# Optional integrations
alive setup telegram    # Telegram bot token + chat ID
alive setup browser     # Install Playwright + Chromium
alive setup webhook     # Slack/Discord/generic webhook URL
```

All config stored at `~/.alive/config.json`. Skills at `~/.alive/skills/`. Database at `~/.alive/alive.db`.

## Roadmap

- [x] Self-evolving skill builder with Battle Mode
- [x] 5 composable integrations
- [x] ALP v0.1 — local network discovery + skill exchange
- [ ] ALP v0.2 — skill reputation, selective sharing
- [ ] ALP v0.3 — internet-scale discovery (DHT)
- [ ] Web UI dashboard
- [ ] Voice interface
- [ ] Mobile companion app
- [ ] Skill marketplace

## Contributing

See [CONTRIBUTING.md](CONTRIBUTING.md). We especially welcome ALP implementations in other languages.

## License

[MIT](LICENSE)
