This package is a small RSScript code agent that talks to an OpenAI-compatible chat-completions endpoint, executes a narrow tool set, and feeds tool results back into the next model turn.
Run it against the local Codex bridge:
AGENT_API_KEY=test_key cargo run -- run examples/packages/code-agentThe example is intentionally structured like a simplified Codex loop:
src/config.rss: environment-derived model, endpoint, API key, loop budget, retry policy, and the write sandbox root.src/protocol.rss: builds the model request JSON. (Response, usage, and tool-call parsing come from therss-chat-completionsdependency viaChatResponse.)src/state.rss: structured chat message history.src/tool_types.rss: tool request/output/action types and shared helpers.src/tool_specs.rss: JSON schemas sent to the model.src/tool_file.rss:read,write, andedit.src/tool_command.rss:shell,rss_check,rss_cmd,rss_ide, andfinish.src/tools.rss: explicitToolRuntimedispatch and chat-history glue.src/main.rss: bounded agent loop.
All knobs are environment-driven (with safe defaults), so the loop budget and network behavior are not hard-coded:
| Env var | Default | Meaning |
|---|---|---|
AGENT_MODEL |
gpt-5.5:medium |
Model name sent to the endpoint. |
AGENT_ENDPOINT |
http://localhost:8080/v1/chat/completions |
Chat-completions URL. |
AGENT_API_KEY |
test_key |
Bearer token. |
AGENT_MAX_STEPS |
8 |
Maximum model turns before the loop stops. |
AGENT_MAX_TOOL_CALLS |
8 |
Maximum tool calls consumed per model turn. |
AGENT_MAX_TOTAL_TOKENS |
1000000 |
Cumulative token budget across the run; once usage_total reaches it the loop stops with an error instead of continuing. |
AGENT_MAX_READ_BYTES |
200000 |
Maximum file size the read tool will load. |
AGENT_MAX_WRITE_BYTES |
200000 |
Maximum new file content size for write/edit/patch tools. |
AGENT_TIMEOUT_MS |
60000 |
Per-request timeout. |
AGENT_MAX_ATTEMPTS |
3 |
HTTP retry attempts (transient failures). |
AGENT_BACKOFF_MS |
500 |
Backoff between retries. |
AGENT_WORKSPACE_ROOT |
target/ |
Write/edit/patch tools are confined to this safe relative prefix. |
AGENT_REPO_ROOT |
RSS_RUN_WORKSPACE_ROOT |
Repository root used for read-only tools and RSScript checks. |
AGENT_PROMPT |
(read-file task) | Override the agent task. |
- Structured history: model turns are stored as chat messages. Tool results
are appended as
role=toolmessages with the original tool call id, not as natural-language transcript text. - Discovery tools:
readandrss_idelet the model inspect source files and indexed interfaces before it edits. - Edit tools:
writeoverwrites files andeditreplaces exact text. - Command tools:
rss_checkandrss_cmdrun structured RSScript commands from the repository root;shellrefuses RSScript commands so language checks stay reviewable. Command execution usesProcessRequestwith explicitcwd, timeout, merged stdout/stderr, and runtime-enforced output caps. - Finish tool:
finishends the loop explicitly with a final answer. - Tool argument enforcement: tool arguments must decode as the declared JSON object shape. Missing required fields or wrong types return an explicit tool error instead of falling back to a default action.
- Read/write scope:
read,rss_check,rss_cmd, andrss_ideresolve safe relative paths fromAGENT_REPO_ROOT.write,edit, andapply_patchare additionally confined toAGENT_WORKSPACE_ROOT, reject absolute paths and..traversal, and cap new content withAGENT_MAX_WRITE_BYTES.readrefuses files larger thanAGENT_MAX_READ_BYTES. - Real checks:
rss_checkruns the package checker and returns status/stdout/stderr. - HTTP errors: a non-success response is logged as a
turn.failedevent and fails the run instead of being parsed as if it were a successful turn. - Budget: the loop is bounded by two budgets. When the step budget
(
AGENT_MAX_STEPS) is exhausted before the task finishes, the agent emits aturn.budget_exhaustedevent and returns an error. The accumulated token usage is also tracked: onceusage_totalreachesAGENT_MAX_TOTAL_TOKENS, the agent emits aturn.token_budget_exhaustedevent and returns an error rather than letting a long run grow without bound. Both stops flow through the samestate.failedexit, somainreturnsErrwith the reason.
The agent should not guess RSScript APIs. It reads the repository root
AGENT.md first, then examples/packages/code-agent/AGENTS.md, uses rss_ide
or direct read calls against schemas/core-package-index.json, then opens the
relevant indexed .rssi files under core/ or rss/*/interface/ before writing
RSScript code.