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

# Agent-Owned Repos

> How agents build up a library of proven code over time

# Agent-Owned Repos

## What This Means

An agent-owned repo is the idea that agents can build up a library of proven code over time, based on execution results rather than one-off code generation.

Instead of generating from scratch every run, agents:

1. **Search** for proven code that already solved similar tasks
2. **Execute** the code in an isolated sandbox environment
3. **Score** the results — AI automatically evaluates code quality and promotes what works
4. **Build a library** — over time, the agent accumulates a growing collection of reliable code

## Quick Start

Pass your chat history as Anthropic-typed messages. The agent handles caching, code reuse, and quality scoring automatically.

<CodeGroup>
  ```python Python theme={null}
  from raysurfer import Agent

  agent = Agent()
  result = await agent.run(
      org_id="acme-corp",
      user_id="user_123",
      messages=[
          {"role": "user", "content": "Generate a quarterly report from our sales data"},
      ],
  )
  ```

  ```typescript TypeScript theme={null}
  import { Agent } from "raysurfer";

  const agent = new Agent();
  const result = await agent.run(
    [{ role: "user", content: "Generate a quarterly report from our sales data" }],
    { orgId: "acme-corp", userId: "user_123" },
  );
  ```
</CodeGroup>

## How Code Quality Improves Over Time

Every time `agent.run()` processes a conversation, it tracks which cached code snippets were retrieved and used. AI automatically evaluates execution results and votes on all the code that contributed:

* **Successful execution** → thumbs up on every cached snippet used → those snippets rank higher in future searches
* **Failed execution** → thumbs down → those snippets get demoted and eventually stop surfacing

This creates a closed loop: execution quality directly determines which code gets reused. Code that consistently produces good results rises to the top. Code that doesn't gets buried — all without any manual intervention.

```
Chat messages → search cached code → execute → produce result
                                                      ↓
                                              AI evaluates quality
                                                      ↓
                                        automatic vote on all
                                        code that contributed
                                                      ↓
                                        good code promoted,
                                        bad code demoted
```

New code generated during execution is also AI-voted at upload time, so it enters the library with an initial quality signal immediately.

## The Core Loop

Under the hood, `agent.run()` wraps two API calls per conversation:

1. **`raysurfer.search()`** — find proven code that already solved similar tasks
2. **`raysurfer.upload()`** — store any new code generated for future reuse

```
Search proven code → Execute → Upload new code → AI scores quality
```

This makes agent behavior more stable over time. Agents start from high-signal code paths and only generate new code when necessary.

## Persistence

The code library persists per organization. Every agent session within the same `org_id` shares the same pool of proven code. This means:

* Code uploaded by one user's session is available to all users in the org
* AI quality scoring affects the ranking for everyone
* The library improves continuously without manual curation

## Sandbox Execution

When agents execute code through Raysurfer, it runs in an isolated environment. This means:

* Code runs safely without affecting your production systems
* Execution results are captured and used for reputation scoring
* Failed code is automatically excluded from future retrieval

## Recommended Rollout

1. Add Raysurfer to one high-frequency workflow first.
2. Track which snippets are repeatedly reused with positive scores.
3. Expand to additional workflows once retrieval quality is stable.

<Note>
  Keep values parameterized in snippets. Hardcode only values you expect to be reused verbatim.
</Note>

<Card title="Need help planning your rollout?" icon="calendar" href="https://calendly.com/raymond-raysurfer/15min">
  Book a 15-minute call and we'll help you pick the right workflows to start with.
</Card>

<CardGroup cols={2}>
  <Card title="Code Reputation Registry" icon="chart-line" href="https://www.raysurfer.com/public_snippets">
    Inspect publicly ranked snippets and quality signals that feed reuse decisions.
  </Card>

  <Card title="How It Works" icon="gear" href="/how-it-works">
    Learn about proven code retrieval and reputation scoring.
  </Card>

  <Card title="Integrations" icon="plug" href="/integrations/overview">
    Add the same loop through Python/TypeScript SDKs, CLI, MCP, skill, or plugin.
  </Card>

  <Card title="Results" icon="chart-bar" href="/results">
    See real-world accuracy and speed improvements.
  </Card>
</CardGroup>
