Code Cache - Semantic Code Caching for AI Agents
This skill enables semantic code caching via the Raysurfer API.
What It Does
When your agent generates and executes code, Code Cache stores it. When a similar task comes up later, the agent can retrieve and run the cached code instead of regenerating it—saving time and tokens.
Setup
Get your API key from the Raysurfer dashboard and configure it:
CODEBLOCK0
Available Commands
Search for cached code
CODEBLOCK1
Search for cached code snippets that match a natural language task description.
Options:
- -
--top-k N — Maximum number of results (default: 5) - INLINECODE1 — Minimum verdict score filter (default: 0.3)
- INLINECODE2 — Display the source code of the top match
Example:
CODEBLOCK2
Get code files for a task
CODEBLOCK3
Retrieve code files ready for execution, with a pre-formatted prompt addition for your LLM.
Options:
- -
--top-k N — Maximum number of files (default: 5) - INLINECODE4 — Output directory (default:
.code_cache)
Example:
CODEBLOCK4
Upload code to cache
CODEBLOCK5
Upload code from an execution to the cache for future reuse.
Options:
- -
--files, -f — Files to upload (required, can specify multiple) - INLINECODE7 — Mark the execution as failed (default: succeeded)
- INLINECODE8 — Disable automatic voting on stored code blocks
Example:
CODEBLOCK6
Vote on cached code
CODEBLOCK7
Vote on whether cached code was useful. This improves retrieval quality over time.
Options:
- -
--up — Upvote / thumbs up (default) - INLINECODE10 — Downvote / thumbs down
- INLINECODE11 — Original task description (optional)
- INLINECODE12 — Code block name (optional)
- INLINECODE13 — Code block description (optional)
Example:
CODEBLOCK8
How It Works
- 1. Cache Hit: When you ask for code similar to something previously executed, Code Cache returns the cached version instantly
- Cache Miss: When no match exists, your agent generates code normally, then Code Cache stores it for future use
- Verdict Scoring: Code that works gets 👍, code that fails gets 👎—retrieval improves over time
API Reference
The skill wraps these Raysurfer API methods:
| Method | Description |
|---|
| INLINECODE14 | Unified search for cached code snippets |
| INLINECODE15 |
Get code files ready for sandbox execution |
|
upload_new_code_snips(task, files_written, succeeded, auto_vote) | Store new code after execution |
|
vote_code_snip(task, code_block_id, code_block_name, code_block_description, succeeded) | Vote on snippet usefulness |
Why Code Caching?
LLM agents repeat the same patterns constantly. Instead of regenerating code every time:
- - 30x faster: Retrieve proven code instead of waiting for generation
- Lower costs: Reduce token usage by reusing cached solutions
- Higher quality: Cached code has been validated and voted on
- Consistent output: Same task = same proven solution
Learn more at raysurfer.com or read the documentation.
代码缓存 - 面向AI代理的语义代码缓存
此技能通过Raysurfer API实现语义代码缓存。
功能说明
当您的代理生成并执行代码时,代码缓存会将其存储。当后续出现类似任务时,代理可以检索并运行缓存的代码,而无需重新生成——从而节省时间和令牌。
配置
从Raysurfer控制台获取您的API密钥并进行配置:
bash
通过环境变量
export RAYSURFER
APIKEY=your
apikey_here
或通过OpenClaw配置
openclaw config set skills.entries.code-cache.apiKey your
apikey_here
可用命令
搜索缓存代码
/code-cache search <任务描述> [--top-k N] [--min-score FLOAT] [--show-code]
搜索与自然语言任务描述匹配的缓存代码片段。
选项:
- - --top-k N — 最大结果数量(默认:5)
- --min-score FLOAT — 最低判定分数筛选(默认:0.3)
- --show-code — 显示最佳匹配的源代码
示例:
/code-cache search 生成季度营收报告
/code-cache search 获取GitHub趋势仓库 --top-k 3 --show-code
获取任务的代码文件
/code-cache files <任务描述> [--top-k N] [--cache-dir DIR]
检索准备执行的代码文件,并附带为您的LLM预格式化的提示补充。
选项:
- - --top-k N — 最大文件数量(默认:5)
- --cache-dir DIR — 输出目录(默认:.code_cache)
示例:
/code-cache files 获取GitHub趋势仓库
/code-cache files 构建图表 --cache-dir ./cached_code
上传代码到缓存
/code-cache upload <任务> --files <路径> [<路径>...] [--failed] [--no-auto-vote]
将执行后的代码上传到缓存以供将来重用。
选项:
- - --files, -f — 要上传的文件(必填,可指定多个)
- --failed — 将执行标记为失败(默认:成功)
- --no-auto-vote — 禁用对存储代码块的自动投票
示例:
/code-cache upload 构建图表 --files chart.py
/code-cache upload 数据管道 -f extract.py transform.py load.py
/code-cache upload 失败尝试 --files broken.py --failed
对缓存代码投票
/code-cache vote <代码块ID> [--up|--down] [--task TEXT] [--name TEXT] [--description TEXT]
对缓存的代码是否有用进行投票。这有助于随时间提高检索质量。
选项:
- - --up — 点赞/竖大拇指(默认)
- --down — 点踩/竖小指
- --task — 原始任务描述(可选)
- --name — 代码块名称(可选)
- --description — 代码块描述(可选)
示例:
/code-cache vote abc123 --up
/code-cache vote xyz789 --down --task 生成报告
工作原理
- 1. 缓存命中:当您请求与之前执行过的代码相似的代码时,代码缓存会立即返回缓存版本
- 缓存未命中:当没有匹配项时,您的代理正常生成代码,然后代码缓存将其存储以供将来使用
- 判定评分:有效的代码获得👍,失败的代码获得👎——检索质量随时间提升
API参考
该技能封装了以下Raysurfer API方法:
| 方法 | 描述 |
|---|
| search(task, topk, minverdictscore) | 统一搜索缓存的代码片段 |
| getcodefiles(task, topk, cache_dir) |
获取准备在沙箱中执行的代码文件 |
| upload
newcode
snips(task, fileswritten, succeeded, auto_vote) | 执行后存储新代码 |
| vote
codesnip(task, code
blockid, code
blockname, code
blockdescription, succeeded) | 对代码片段的有用性进行投票 |
为什么使用代码缓存?
LLM代理会不断重复相同的模式。与其每次都重新生成代码:
- - 快30倍:检索经过验证的代码,而不是等待生成
- 降低成本:通过重用缓存的解决方案减少令牌使用
- 更高质量:缓存的代码已经过验证和投票
- 一致输出:相同任务 = 相同的经过验证的解决方案
了解更多请访问raysurfer.com或阅读文档。