API Reference for rune-agent¶
rune_agent ¶
Rune coding agent -- recursive code generation with parametric memory.
Classes¶
RuneState ¶
Bases: TypedDict
State for the Rune coding agent recursive loop.
Attributes:
| Name | Type | Description |
|---|---|---|
task_description |
str
|
Natural language description of the coding task. |
task_type |
str
|
Category of task (e.g. 'function', 'class', 'refactor'). |
test_suite |
str
|
Test code that the generated solution must pass. |
adapter_ids |
list[str]
|
LoRA adapter IDs to load for parametric memory. |
session_id |
str
|
Unique identifier for trajectory persistence (UUID4). |
attempt_count |
int
|
Current attempt number (0-indexed, incremented by reflect). |
max_attempts |
int
|
Maximum number of generation attempts allowed. |
generated_code |
str
|
Code produced by the generate node. |
stdout |
str
|
Standard output from executing generated code. |
stderr |
str
|
Standard error from executing generated code. |
exit_code |
int
|
Process exit code from execution (0 = success). |
tests_passed |
bool
|
Whether the test suite passed on this attempt. |
test_count |
int
|
Number of unittest tests that ran. |
tests_ran |
bool
|
Whether any unittest tests actually executed. |
trajectory |
list[dict[str, Any]]
|
List of per-attempt records for parametric memory training. |
outcome |
Optional[str]
|
Terminal result -- 'success', 'exhausted', or None if still running. |
Functions¶
create_graph ¶
create_graph() -> Any
Create and compile the Rune agent workflow graph.
The graph follows this flow: START -> generate -> execute -> reflect -> [should_retry] -> generate (retry) OR save_trajectory -> END
Returns:
| Type | Description |
|---|---|
Any
|
Compiled StateGraph ready for execution. |
Example
graph = create_graph() graph is not None True
Source code in services/rune-agent/src/rune_agent/graph.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
get_graph ¶
get_graph() -> Any
Get or create the compiled graph instance (thread-safe singleton).
Uses double-checked locking so the expensive create_graph() call is only made once, even if multiple threads call get_graph() concurrently.
Returns:
| Type | Description |
|---|---|
Any
|
Compiled StateGraph instance. |
Source code in services/rune-agent/src/rune_agent/graph.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
Modules¶
graph ¶
LangGraph workflow for the Rune coding agent recursive loop.
Supports two modes: 1. Standard loop (create_graph): generate → execute → reflect → retry/save 2. Single iteration (create_single_iteration_graph): generate → execute → reflect → END. Used by the outer rune_runner iteration loop where the hypernetwork produces a new adapter between iterations.
Classes¶
Functions¶
should_retry ¶
should_retry(
state: RuneState,
) -> Literal["generate", "save_trajectory"]
Route from reflect: retry if attempts remain and tests failed, else save.
This is a REAL implementation, not a stub: - If tests passed -> save_trajectory (success) - If attempt_count >= max_attempts -> save_trajectory (exhausted) - Otherwise -> generate (retry)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RuneState
|
Current agent state after reflection. |
required |
Returns:
| Type | Description |
|---|---|
Literal['generate', 'save_trajectory']
|
Next node name: 'generate' to retry or 'save_trajectory' to finish. |
Example
state = {"tests_passed": False, "attempt_count": 0, "max_attempts": 3} should_retry(state) 'generate' state2 = {"tests_passed": True, "attempt_count": 1, "max_attempts": 3} should_retry(state2) 'save_trajectory'
Source code in services/rune-agent/src/rune_agent/graph.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | |
create_graph ¶
create_graph() -> Any
Create and compile the Rune agent workflow graph.
The graph follows this flow: START -> generate -> execute -> reflect -> [should_retry] -> generate (retry) OR save_trajectory -> END
Returns:
| Type | Description |
|---|---|
Any
|
Compiled StateGraph ready for execution. |
Example
graph = create_graph() graph is not None True
Source code in services/rune-agent/src/rune_agent/graph.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | |
create_single_iteration_graph ¶
create_single_iteration_graph() -> Any
Create a graph for one iteration: generate → execute → reflect → END.
Used by rune_runner's outer iteration loop. Each iteration runs one generate/execute/reflect cycle, then returns control to the outer loop which runs the hypernetwork to produce a new adapter for the next iteration.
Returns:
| Type | Description |
|---|---|
Any
|
Compiled StateGraph for single-iteration execution. |
Source code in services/rune-agent/src/rune_agent/graph.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
get_graph ¶
get_graph() -> Any
Get or create the compiled graph instance (thread-safe singleton).
Uses double-checked locking so the expensive create_graph() call is only made once, even if multiple threads call get_graph() concurrently.
Returns:
| Type | Description |
|---|---|
Any
|
Compiled StateGraph instance. |
Source code in services/rune-agent/src/rune_agent/graph.py
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 | |
nodes ¶
Node functions for the Rune coding agent recursive loop.
Classes¶
Functions¶
generate_node
async
¶
generate_node(state: RuneState) -> dict[str, Any]
Generate code for the given task using the inference layer.
Calls the LLM (with optional LoRA adapters) to produce a code solution for the task description.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RuneState
|
Current agent state with task description and context. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
State update dict with generated_code key. |
Example
state = {"task_description": "Write fibonacci", "task_type": "function", ... "test_suite": "assert fib(5) == 5", "adapter_ids": []} result = await generate_node(state) 'generated_code' in result True
Source code in services/rune-agent/src/rune_agent/nodes.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | |
execute_node
async
¶
execute_node(state: RuneState) -> dict[str, Any]
Execute the generated code in a sandboxed environment.
Runs the generated code against the test suite in an isolated subprocess and captures stdout, stderr, and exit code.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RuneState
|
Current agent state with generated code and test suite. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
State update dict with stdout, stderr, exit_code, and tests_passed keys. |
Example
state = {"generated_code": "def fib(n): return n", "test_suite": ""} result = await execute_node(state) 'tests_passed' in result True
Source code in services/rune-agent/src/rune_agent/nodes.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 | |
reflect_node
async
¶
reflect_node(state: RuneState) -> dict[str, Any]
Reflect on execution results and record the attempt in trajectory.
Increments the attempt counter and appends the current attempt's data to the trajectory list. Does not make any LLM calls.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RuneState
|
Current agent state with execution results. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
State update dict with incremented attempt_count and extended trajectory. |
Example
state = {"attempt_count": 0, "generated_code": "def fib(n): pass", ... "exit_code": 1, "tests_passed": False, "trajectory": [], ... "stdout": "", "stderr": ""} result = await reflect_node(state) result['attempt_count'] 1
Source code in services/rune-agent/src/rune_agent/nodes.py
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 | |
save_trajectory_node
async
¶
save_trajectory_node(state: RuneState) -> dict[str, Any]
Save the completed trajectory for parametric memory training.
Persists the trajectory to disk via record_trajectory() and determines the final outcome based on whether tests passed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state
|
RuneState
|
Current agent state with complete trajectory and outcome. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
State update dict with outcome key ('success' or 'exhausted'). |
Example
state = {"tests_passed": True, "session_id": "abc", "trajectory": [], ... "task_description": "", "task_type": "", "adapter_ids": []} result = await save_trajectory_node(state) result['outcome'] 'success'
Source code in services/rune-agent/src/rune_agent/nodes.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 | |
state ¶
State definition for the Rune coding agent recursive loop.
Classes¶
RuneState ¶
Bases: TypedDict
State for the Rune coding agent recursive loop.
Attributes:
| Name | Type | Description |
|---|---|---|
task_description |
str
|
Natural language description of the coding task. |
task_type |
str
|
Category of task (e.g. 'function', 'class', 'refactor'). |
test_suite |
str
|
Test code that the generated solution must pass. |
adapter_ids |
list[str]
|
LoRA adapter IDs to load for parametric memory. |
session_id |
str
|
Unique identifier for trajectory persistence (UUID4). |
attempt_count |
int
|
Current attempt number (0-indexed, incremented by reflect). |
max_attempts |
int
|
Maximum number of generation attempts allowed. |
generated_code |
str
|
Code produced by the generate node. |
stdout |
str
|
Standard output from executing generated code. |
stderr |
str
|
Standard error from executing generated code. |
exit_code |
int
|
Process exit code from execution (0 = success). |
tests_passed |
bool
|
Whether the test suite passed on this attempt. |
test_count |
int
|
Number of unittest tests that ran. |
tests_ran |
bool
|
Whether any unittest tests actually executed. |
trajectory |
list[dict[str, Any]]
|
List of per-attempt records for parametric memory training. |
outcome |
Optional[str]
|
Terminal result -- 'success', 'exhausted', or None if still running. |