Skip to main content

Python SDK for RaySurfer - code block caching and retrieval for AI agents with Claude Agent SDK integration

Project description

RaySurfer Python SDK

Store and retrieve code blocks for AI agents with semantic search and verdict-aware scoring.

Install

pip install raysurfer

Quick Start

from raysurfer import RaySurfer

rs = RaySurfer(api_key="your-api-key")

# Store a code block
result = rs.store_code_block(
    name="fetch_weather",
    source="""
def fetch_weather(city: str) -> dict:
    import requests
    resp = requests.get(f"https://api.weather.com/{city}")
    return resp.json()
""",
    entrypoint="fetch_weather",
    language="python",
    description="Fetches weather data for a city",
    tags=["api", "weather"],
)
print(f"Stored: {result.code_block_id}")

# Retrieve code blocks by task
results = rs.retrieve("get weather data for a location")
for match in results.code_blocks:
    print(f"{match.code_block.name}: {match.score}")

# Get the single best match with verdict-aware scoring
best = rs.retrieve_best("fetch current temperature")
if best.best_match:
    print(f"Best: {best.best_match.code_block.name}")
    print(f"Confidence: {best.retrieval_confidence}")

Async Usage

from raysurfer import AsyncRaySurfer

async def main():
    async with AsyncRaySurfer(api_key="your-api-key") as rs:
        results = await rs.retrieve("parse JSON data")
        print(results.code_blocks)

Store Execution Records

Track how code blocks perform to improve future retrieval:

from raysurfer import RaySurfer, ExecutionState, AgentVerdict

rs = RaySurfer(api_key="your-api-key")

# After running a code block
rs.store_execution(
    code_block_id="cb_xxx",
    triggering_task="get weather for NYC",
    input_data={"city": "NYC"},
    output_data={"temp": 72, "conditions": "sunny"},
    execution_state=ExecutionState.COMPLETED,
    duration_ms=150,
    verdict=AgentVerdict.THUMBS_UP,
)

API Reference

RaySurfer / AsyncRaySurfer

Store methods:

  • store_code_block(...) - Store a new code block
  • store_execution(...) - Store an execution record with optional verdict

Retrieve methods:

  • retrieve(task) - Semantic search for code blocks
  • retrieve_best(task) - Get the single best match with scoring
  • get_few_shot_examples(task) - Get examples for code generation
  • get_task_patterns(...) - Get proven task→code mappings

Verdict System

RaySurfer uses thumbs up/down verdicts that are independent of execution state:

  • A technical error can be thumbs up (correct validation behavior)
  • A successful execution can be thumbs down (useless output)

This allows the system to learn which code blocks are actually useful, not just which ones run without errors.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

raysurfer-0.2.0.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

raysurfer-0.2.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file raysurfer-0.2.0.tar.gz.

File metadata

  • Download URL: raysurfer-0.2.0.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for raysurfer-0.2.0.tar.gz
Algorithm Hash digest
SHA256 77ed994f0cd53c3a9803134239b2cbf5e242707bf75a204e54f5a6fdf9290002
MD5 1036b2ed8c194e9dca58b532dbca684f
BLAKE2b-256 f8e63ef608642596725bd6d704c4163374924de80cd975a4f7d60ad43e8de222

See more details on using hashes here.

File details

Details for the file raysurfer-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: raysurfer-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.7

File hashes

Hashes for raysurfer-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f3308b3867f1a386ebc27003d71f4b9f3a0faf69d96689a3d9fc138e6d4dc333
MD5 4f0550334ff65114de8cba2d5b075291
BLAKE2b-256 a101342f05c5328b1133d65d0d67eb0839041f0e08d9abbdce117768cca07961

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page