Graph and state#
The agent topology: nodes wired by edges, entered at a hub. See Customize agents and tools for the narrative version.
adda.Graph
dataclass
#
Agent graph passed to :class:~agent_runtime.AgenticRun.
Declares which agents exist, which directed delegation edges connect them, and which agent starts the run. Loops are permitted.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nodes
|
dict[str, Agent]
|
Maps unique agent names to :class: |
required |
edges
|
sequence of Edge
|
Directed delegation edges. An agent with no outgoing edges
receives no |
()
|
entry
|
str
|
Name of the agent that receives the initial briefing. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any edge endpoint names an undeclared node, or if entry is not declared. |
Source code in src/adda/_src/backends/base.py
393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | |
nodes: dict
instance-attribute
#
edges: tuple = ()
class-attribute
instance-attribute
#
entry: str = None
class-attribute
instance-attribute
#
_MERMAID_COLOURS = {'StrategizerAgent': ('#1d4ed8', '#1e3a8a'), 'LiteratureReviewAgent': ('#6d28d9', '#4c1d95'), 'DataGeneratorAgent': ('#b45309', '#7c2d12'), 'F3dasmImplementerAgent': ('#15803d', '#14532d'), 'AdversarialCritiqueAgent': ('#b91c1c', '#7f1d1d'), 'DebuggerAgent': ('#475569', '#1e293b')}
class-attribute
instance-attribute
#
_MERMAID_FALLBACK = [('#0f766e', '#134e4a'), ('#a16207', '#713f12'), ('#be185d', '#831843'), ('#4338ca', '#312e81')]
class-attribute
instance-attribute
#
outgoing(name: str) -> list[str]
#
Return target names for all edges out of name.
Source code in src/adda/_src/backends/base.py
450 451 452 | |
incoming(name: str) -> list[str]
#
Return source names for all edges into name.
Source code in src/adda/_src/backends/base.py
454 455 456 | |
edge(source: str, target: str) -> Edge | None
#
Return the Edge from source to target, or None if absent.
Source code in src/adda/_src/backends/base.py
458 459 460 461 462 463 | |
to_mermaid() -> str
#
Return a styled Mermaid flowchart for this graph.
Generated from the live spec: node labels carry each agent's class, role, and a short description; nodes are coloured by agent class; edges from the entry node render as solid delegation arrows and edges from worker nodes as dotted consultation arrows. Paste at https://mermaid.live or any Mermaid-aware renderer (GitHub markdown, Jupyter, VS Code).
Source code in src/adda/_src/backends/base.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 | |
adda.Edge
dataclass
#
A directed delegation edge between two named agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
source
|
str
|
Name of the agent that is allowed to call |
required |
target
|
str
|
Name of the agent that receives the delegated task. |
required |
preamble
|
str
|
Text prepended to the task message when this edge is traversed. |
''
|
Source code in src/adda/_src/backends/base.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | |
adda.Agent
#
Base class for all agentic nodes in a Graph.
Subclasses override class-level attributes (system_prompt,
tools, etc.) to configure behaviour. Behavioural differences
belong in class attributes, not constructor arguments.
Tool system — three categories:
tools: frozenset[str] declares tools from two categories:
-
Native backend tools — names from :data:
NATIVE_TOOL_NAMES("Bash","Read","Write", etc.). The runtime passes these to the backend session's native tool executor. -
Protocol closure tools — names from :data:
PROTOCOL_CLOSURE_NAMES("Done","WriteNote","ReadNote"). The runtime builds Python callables for these and passes them asclosure_toolsto the session factory. -
Topology-injected tools —
"Delegate","Parallel","Debate","Retry"(outgoing edges),"Ask"(entry node), and"SendMessage"(every node, regardless of edges). Never declare these inAgent.tools. The runtime injects them automatically from the graph topology; any declaration here is ignored. -
External MCP server tools — names declared in
extra_allowed_tools(e.g."arxiv_search_papers"). The runtime passes these to the backend together withmcp_servers, a dict of{server_name: McpStdioServerConfig}that declares which external MCP servers to start.
Default is frozenset() — no tools (opt-in, conservative).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str or None
|
Model identifier. |
None
|
Source code in src/adda/_src/backends/base.py
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 283 284 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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
system_prompt: str = ''
class-attribute
instance-attribute
#
tools: frozenset[str] = frozenset()
class-attribute
instance-attribute
#
reset_on_checkpoint: bool = True
class-attribute
instance-attribute
#
description: str = ''
class-attribute
instance-attribute
#
role: str = 'worker'
class-attribute
instance-attribute
#
model: str | None = None
class-attribute
instance-attribute
#
backend: str | None = None
class-attribute
instance-attribute
#
base_url: str | None = None
class-attribute
instance-attribute
#
base_prompt: str | None = None
class-attribute
instance-attribute
#
mcp_servers: dict = {}
class-attribute
instance-attribute
#
extra_allowed_tools: frozenset[str] = frozenset()
class-attribute
instance-attribute
#
max_history_pairs: int = 5
class-attribute
instance-attribute
#
report_sections: tuple[str, ...] = ('### Actions taken', '### Conclusions', '### Numbers')
class-attribute
instance-attribute
#
forward() -> None
#
ADAS hook — override for inspectable Python orchestration.
Source code in src/adda/_src/backends/base.py
324 325 | |
build_closure_tools(study_dir: Path, delegation_id: str | None = None, lit_reviewer_notes_dir: Path | None = None) -> dict
#
Return runtime closure tools for this agent.
Called by the runtime when constructing the worker adapter so agents can inject Python callables (e.g. corpus management tools) without declaring them in Agent.tools.
The default gives EVERY agent read-only lookup against the study's persistent literature corpus (ConsultLiterature) — the corpus is shared, queryable infrastructure (see LiteratureCorpus), the same way QueryStore lets every node read the canonical evaluation ledger without delegating to the data generator. ACQUIRING a new paper (CorpusAdd, external search) stays literature_reviewer-only: finding and vetting a new paper needs judgment a raw tool call can't supply, so it stays gated behind an actual delegation — see LiteratureReviewAgent.build_closure_tools, which overrides this method entirely (the same ConsultLiterature plus CorpusAdd) and does not call super().
Override in a subclass to replace this default entirely.
Source code in src/adda/_src/backends/base.py
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 | |
adda.Node
#
One node in the agent graph.
inspect.getsource(Node._orchestrate) reads the routing logic every
node runs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
adapter
|
Any
|
The LLM adapter this node speaks through. |
required |
name
|
str
|
The node's name in the graph. This is what distinguishes one agent from another — there is no per-agent node class. |
'node'
|
outgoing
|
list[str] | tuple[str, ...]
|
Names of the nodes this one may delegate to. Empty means |
()
|
spec
|
Any
|
The whole :class: |
None
|
report_sections
|
tuple[str, ...] | None
|
This agent's own declared report contract and toolset. |
None
|
agent_tools
|
tuple[str, ...] | None
|
This agent's own declared report contract and toolset. |
None
|
Source code in src/adda/_src/nodes/node.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 169 170 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 238 239 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 283 284 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 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
_current_run_dir
property
#
This run's root, derived from the notes dir the graph state sets.
run_dir arrives on the state, not on the node, and only
_current_notes_dir (<run>/debug/strategizer_notes) is kept
from it — so the run root is that path's grandparent. None
before the first invoke, which callers must tolerate.
_awake_slots = None
class-attribute
instance-attribute
#
adapter = adapter
instance-attribute
#
_name = name
instance-attribute
#
_outgoing = list(outgoing)
instance-attribute
#
_spec = spec
instance-attribute
#
_stop_tick() -> str
#
Raw notice text for the entry node, "" when there is nothing new (the caller marks it as an adda notice).
Idempotent and cheap: one small file read until a request is seen. Only the node that runs a turn (the one holding the run's start time) acts; a worker node's checkpoints leave the request alone.
Source code in src/adda/_src/nodes/stop.py
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 | |
_stop_nodes() -> list[Any]
#
Source code in src/adda/_src/nodes/stop.py
144 145 | |
_stop_wind_down() -> list[str]
#
Tell every live delegation to report now. Returns their ids.
Source code in src/adda/_src/nodes/stop.py
147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
_stop_cancel_stragglers() -> list[str]
#
Past the grace: detach what has not reported, and say so.
No placeholder retrospective is written for a straggler — it never gave one, and the record must say that rather than invent it.
Source code in src/adda/_src/nodes/stop.py
162 163 164 165 166 167 168 169 170 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 | |
_stop_refusal() -> str | None
#
The Delegate refusal while a stop is active, else None.
Source code in src/adda/_src/nodes/stop.py
202 203 204 205 206 207 208 209 | |
_stop_consume() -> None
#
Source code in src/adda/_src/nodes/stop.py
211 212 213 214 | |
_request_wind_down(*, reason: str, termination: str, run_dir: Any = None, grace_s: float = DEFAULT_GRACE_S) -> bool
#
A backstop asks for the graceful path instead of halting. False when it cannot (no run directory, or the file cannot be written), in which case the caller halts as it always did.
Source code in src/adda/_src/nodes/stop.py
216 217 218 219 220 221 222 223 224 225 226 227 228 | |
_wind_down_overdue() -> bool
#
The grace for the workers plus an equal one for the entry node's own retrospective round has passed: the hard halt may fire.
Source code in src/adda/_src/nodes/stop.py
230 231 232 233 234 | |
_stop_termination() -> str
#
Source code in src/adda/_src/nodes/stop.py
236 237 | |
_recorded_retrospective_ids() -> set[str]
#
Source code in src/adda/_src/nodes/stop.py
239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 | |
_missing_retrospectives() -> list[str]
#
Delegations that ended without a recorded retrospective.
Source code in src/adda/_src/nodes/stop.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
_log_lost_workers() -> None
#
A resume after a crash: delegations the delegation log last saw RUNNING died with the process. They are named, never given invented retrospective text.
Source code in src/adda/_src/nodes/stop.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 | |
_log_missing_retrospectives(why: str) -> None
#
Source code in src/adda/_src/nodes/stop.py
291 292 293 294 295 296 | |
_init_orchestration(*, name: str, outgoing: list[str], spec: Any, study_dir: Any = None, interactive: bool = False, max_ask: int = 1, worker_adapters: dict | None = None, notes_dir: Any = None, workspace_dir: Any = None, delegation_log: DelegationLog | None = None) -> None
#
Set up the delegation registry, the ledgers and the routing tools.
Runs for every node (Node.__init__ no longer branches on
outgoing). The registry/routing state below is inert when
outgoing is empty — Delegate() just has no valid target — so
there is no harm running it unconditionally. Epistemic OWNERSHIP is
the one thing that must stay gated on having outgoing edges (see
_owns_epistemics below): notes_dir is passed identically to
every node by graph_builder.py, and a node with nobody to
delegate to must never acquire the hypothesis/milestone ledgers just
because it was handed a path.
study_dir/workspace_dir/delegation_log are already set by
:meth:Node._init_capabilities, which runs first for every node —
not re-set here.
Source code in src/adda/_src/nodes/orchestration.py
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 | |
_install_epistemics() -> None
#
Build (or rebuild at a new path) everything notes_dir owns.
THE one construction site for the hypothesis ledger, the milestone
ledger, the science monitor and telemetry. There used to be two: the
constructor built the ledger, and _absorb_state — which runs at the
start of every turn — rebuilt it with if self._ledger is None,
knowing nothing about why the constructor had left it None. Three
consequences, all of them silent:
graph_builderused to handnotes_dirto the entry node alone, so it alone owned the ledgers; any other orchestrating node re-acquired one on its first turn, undoing that decision. (It now hands the realnotes_dirto every orchestrating node, so this particular inconsistency no longer applies — kept here as the historical reason_install_epistemicsexists as one site.)- Only the ledger was re-pointed when the run's notes dir differed from the constructor's; the milestone ledger and telemetry kept writing to the stale path.
- The science monitor, built once in the constructor, was never rebuilt at all — so a node whose ledger was resurrected ran with the ledger ON and the monitor OFF.
Ownership is fixed at construction (_owns_epistemics); this only
ever rebuilds at a corrected path, never grants ownership.
Source code in src/adda/_src/nodes/orchestration.py
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 238 239 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 | |
_log_status(delegation_id: str) -> tuple[str | None, str]
#
Return (status, deliverable) for delegation_id from the persistent log, or (None, "") if the log has no such delegation.
Source code in src/adda/_src/nodes/orchestration.py
290 291 292 293 294 295 296 297 298 | |
_pending_delegations() -> list[str]
#
In-flight delegations, reconciled against the authoritative log.
A delegation the log shows terminal (DONE/FAILED) is never reported pending, even if the in-memory cache still says "Working". That stale state is what made Done()'s liveness gate refuse forever and kill run4 by watchdog after it had already found the optimum (audit BF-0/BF-2).
Source code in src/adda/_src/nodes/orchestration.py
300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
_find_datagenerator_name() -> str | None
#
Name of the first connected datagenerator worker, or None.
Its presence means a canonical ground-truth source CAN be authored and registered for this study.
Source code in src/adda/_src/nodes/orchestration.py
321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 | |
_canonical_source_registered() -> bool
#
True if a canonical ground-truth source is resolvable.
Reads run_config.json: an evaluator entrypoint OR a lookup pool counts as a registered source. Best-effort — on any read failure, assume not registered (the nudge is soft, so a false 'no' just costs one notice).
Source code in src/adda/_src/nodes/orchestration.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | |
_drain_operator_notes() -> str
#
Operator notes queued by a human in the viewer, marked as coming from the operator; "" when none. Notes addressed to a RUNNING delegation are routed to that worker instead. Claims the queue destructively, so whatever calls this owns delivery.
Source code in src/adda/_src/nodes/orchestration.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 | |
_drain_entry_notices() -> str
#
Notices a campaign process queued for the entry node (the oracle was edited, say); "" for any other node or when none. The entry node holds no delegation id, so the backends' post-tool hook never reaches its queue; its next tool call does.
Source code in src/adda/_src/nodes/orchestration.py
426 427 428 429 430 431 432 433 434 435 436 437 | |
_drain_notifications() -> str
#
Return and clear any pending push notifications, or empty string.
Source code in src/adda/_src/nodes/orchestration.py
439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 | |
_delegation_entry(delegation_id: str) -> tuple[Any, dict] | None
#
(owning node, registry entry) of a delegation, or None.
The entry lives in the registry of the node that DELEGATED (its delegator), not of the node running the work; the tools a worker calls are bound to the worker's own node, so a worker looking up its own delegation must search across the graph's nodes. Delegation ids come from one graph-wide log, so at most one node owns an id.
Source code in src/adda/_src/nodes/orchestration.py
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 | |
_get_delegator_cond(identity: str) -> threading.Condition
#
The one Condition a given delegator identity waits on and is
woken through (SendMessage, spec 12). identity is a
delegation_id or "entry" — see __init__'s comment on
_delegator_conds. Lazily created, race-free.
Source code in src/adda/_src/nodes/orchestration.py
526 527 528 529 530 531 532 533 534 535 536 | |
_truncate_for_notice(text: str, n: int = 100) -> str
staticmethod
#
Source code in src/adda/_src/nodes/orchestration.py
538 539 540 541 | |
_pending_for_you(identity: str) -> str
#
What identity (a delegator: "entry" or a delegation id
of a node that is ITSELF delegating further) currently owes,
computed FRESH on every call -- never a drained queue, since
"nothing pending" must read as silence indefinitely, not just
until the first drain (spec 12 design item 10(a): "at minimum,
every agent must always KNOW what it currently owes ... or
nothing (in which case: silence, not a notice for its own
sake)").
Four kinds. As a DELEGATOR (entry.get("parent") == identity
-- never a sibling's or a nested child's): a report open for
review (OpenForReview), a finished delegation (Done/Errored)
not yet collected via Wait, and an unread SendMessage question
sitting in a child's own to_delegator queue. As a WORKER (identity is itself a
registry entry, i.e. this node is mid-delegation): an unread
SendMessage from ITS OWN delegator sitting in that entry's
to_worker queue. Every queue peek (never a pop -- that stays
Wait's/SendMessage's job) shares ONE lock acquisition with its
own check, under the SAME Condition/lock the queue's real
consumer uses (the check-then-pop race rule applies just as much
to a check-then-PEEK). Returns "" when none apply -- the common
case, deliberately silent.
Source code in src/adda/_src/nodes/orchestration.py
543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 | |
_build_routing_closures() -> dict
#
Source code in src/adda/_src/nodes/orchestration.py
623 624 625 | |
_wrap_closure(fn: Any, node_name: str) -> Any
#
Return a version of fn that records ERROR returns and exceptions.
Uses functools.wraps so inspect.signature() follows wrapped to the original function — _infer_schema_from_callable must see the real parameter names, not (args, *kwargs).
Also coerces string-typed arguments to int/float/bool when the function annotation requests it (handles Ollama passing "5" for an int parameter).
And it is where pending notices reach the agent: whatever
_drain_notifications holds is APPENDED to the tool's result — after
it, so a result's leading word stays what callers dispatch on ("Done",
"Working", "ERROR:", an id like "H3"). That
used to be hand-copied into 18 tool bodies and missing from the rest —
the store tools never delivered a notice — so whether the agent heard
about a finished delegation depended on which tool it happened to
call. A tool that places notices itself (the status poll keeps its
status word first; Wait drains while it blocks; Done composes its own
reply) still does, and finds the queue already empty here. A
worker's closures pass through here too, and are never drained into.
Source code in src/adda/_src/nodes/orchestration.py
627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | |
_orchestrate(state: AgenticState) -> Any
#
One orchestration turn, in the order it happens.
Absorb the run state onto the node, work out what the agent must be
TOLD this turn, invoke it once, then route on what it did. Every step
is a method below, named for its step; a turn ends in exactly one of
three ways, which :meth:_route_turn states.
Source code in src/adda/_src/nodes/orchestration.py
767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 | |
_absorb_state(state: AgenticState) -> None
#
Copy the run state the node's TOOLS read onto the node itself.
The closures reach their context through node.…, not through
AgenticState, so anything a tool needs has to land here first.
Source code in src/adda/_src/nodes/orchestration.py
796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 | |
_ledgered_eval_total(floor: int) -> int
#
The run's eval count, preferring the ledger over an accumulator.
The canonical ledger is the source of truth: a killed/cancelled
delegation flushes rows the state accumulator never sees, so the
accumulator undercounts. Summed across the canonical store AND every
design namespace — namespace evals were invisible to the run total and
to the soft budget. floor keeps the accumulator for lookup-direct
studies with no instrumented store.
Source code in src/adda/_src/nodes/orchestration.py
852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 | |
_budget_warnings(state: AgenticState) -> list[dict]
#
Advisory budget messages for this turn.
The time budget is a SOFT constraint — warnings only; the run is never force-terminated for exceeding it. A separate run-level backstop (RUN_BACKSTOP_MULTIPLE x budget) bounds runaway cost.
Source code in src/adda/_src/nodes/orchestration.py
875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 | |
_reset_for_turn() -> list[str]
#
A1/A2: clear per-turn state; return the notifications to deliver.
Working entries are preserved so loopbacks don't orphan live delegations whose background threads are still running.
Source code in src/adda/_src/nodes/orchestration.py
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 | |
_compose_messages(state: AgenticState, budget_warnings: list[dict], pending_notifs: list[str]) -> list[dict]
#
The conversation plus everything injected in-band this turn.
Everything after the conversation itself is adda speaking to the agent — a budget warning, the no-source nudge, the milestone backlog, a pushed notification — arriving in the SAME role ("user") the human's own task arrives in. Marked, for the same reason tool-result notices are (nodes/notices.py): unmarked, neither the agent nor a reader can tell the runtime's nudge from the human's brief, and the viewer cannot style it as anything else.
Source code in src/adda/_src/nodes/orchestration.py
956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 | |
_constraint_refresh() -> list[dict]
#
This turn's constraint snapshot, recomputed NOW.
The entry node used to be the one call site that did not re-snapshot.
agent_runtime rendered a snapshot once at run start and
concatenated it onto the problem statement, and that string is the
standing first user turn — re-sent verbatim on every later turn, so
the numbers inside it could never advance. Observed on run
20260917T141603: four consecutive strategizer turns spanning 23.5
minutes all read "2.7min/60.0min used (5%)", while the true figure at
turn 4 was 26.2min (44%).
The orchestrator was not blind -- every delegation report carries a
fresh snapshot (_append_budget_report) -- which made this a
CONTRADICTION rather than an absence: a frozen block and live blocks
in one context. Worse, the frozen copy lived in the first user turn,
which the context trim pins and never evicts, so it was the one
guaranteed to survive while the fresh ones aged out.
Recomputing per turn is what constraint_snapshot.py already asks
of every caller: "call this at every delegation boundary rather than
caching a value from earlier ... its entire purpose depends on being
current". The orchestrator is the node that decides how much more to
attempt, so it is the node that most needs the live clock.
Source code in src/adda/_src/nodes/orchestration.py
986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 | |
_no_source_nudge() -> list[dict]
#
Recommend registering a canonical source (soft, ≤3×).
If this graph has a datagenerator (so a canonical ground-truth source CAN be authored) but none is registered, recommend delegating to it. Without a registered source every evaluation lands off-ledger and nothing is reproducible from the canonical store. Soft and capped — never blocks; the strategizer may ignore it for a genuinely source-free study.
Source code in src/adda/_src/nodes/orchestration.py
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 | |
_backlog_announcement() -> list[dict]
#
Announce the process backlog ONCE, at the start of the run.
As a conversation message, so the agent cannot claim it didn't know these gate the implementer. Injected the first time this node runs.
Source code in src/adda/_src/nodes/orchestration.py
1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 | |
_invoke_turn(messages: list[dict]) -> Any
#
Run one model turn and account for what it spent.
Source code in src/adda/_src/nodes/orchestration.py
1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | |
_route_turn(state: AgenticState, ai_msg: Any) -> Any
#
A turn ends in exactly one of three ways.
- Work is still in flight → re-prompt, free (no attempt spent)
- It stopped without closing → re-prompt, bounded (3 attempts)
- Otherwise → the run ends
Reproduction is owned entirely by the Done() gate (it runs the controlled gate before any close and declares a FAILED run after a bounded number of sighted attempts — see RunNotebook(gate=True)), so there is no separate post-accept repro check here; this handles only deliverable presence and un-accepted termination.
Source code in src/adda/_src/nodes/orchestration.py
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 | |
_reprompt_while_working(ai_msg: Any, accepted: bool, missing: list) -> Any | None
#
Delegations still running: re-prompt WITHOUT spending an attempt.
A healthy delegation still in flight is WORK IN PROGRESS, not a failed finish: the deliverables usually depend on its result, and it WILL report. Spending a bounded finish-attempt on it means a slow-but-healthy delegation (run-4: D004 at ~2.5 evals/s, ~100s from done, with wall budget to spare) burns 3 "finish attempts" across turns and force- terminates the run UNGATED. The run's time backstop (run_backstop_multiple x budget, checked each turn) bounds a delegation that truly hangs.
Source code in src/adda/_src/nodes/orchestration.py
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 | |
_reprompt_unfinished(ai_msg: Any, accepted: bool, missing: list) -> Any | None
#
Bounded re-prompt when the turn ended without an accepted close.
Source code in src/adda/_src/nodes/orchestration.py
1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 | |
_working_delegations() -> list[str]
#
Delegation ids still in flight right now.
Source code in src/adda/_src/nodes/orchestration.py
1222 1223 1224 1225 1226 1227 1228 | |
_terminate_run(state: AgenticState, ai_msg: Any, accepted: bool, missing: list) -> Any
#
Close the run: final counts, banner, ghost flush, terminal Command.
Source code in src/adda/_src/nodes/orchestration.py
1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 | |
_banner(summary: str, accepted: bool, missing: list) -> str
#
Prepend the UNGATED banner when the run ends without an accepted Done().
A FAILED-reproduction close carries its own ⛔ banner in the route summary and IS accepted=done, so it is not re-banner'd here.
Source code in src/adda/_src/nodes/orchestration.py
1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | |
_flush_ghost_delegations() -> None
#
Close out delegations whose threads die with the interpreter.
Daemon threads still alive when the run closes are killed at process exit — their run() never reaches the DONE/FAILED record write, leaving orphan RUNNING entries in the log. Write an INTERRUPTED terminal record for each so query_all() (last-wins) collapses to a closed state instead of RUNNING.
Source code in src/adda/_src/nodes/orchestration.py
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 | |
_missing_deliverables(state: AgenticState) -> list[str]
#
Return required deliverable paths not present at study_dir yet.
The single deliverable (pipeline.ipynb) is required, authored before Done() is accepted, UNLESS the study turns off pipeline_deliverable — it is the human-readable recipe AND the reproduction in one notebook: the runtime executes it lazily (see _reproduction_gate) to verify the headline re-derives from the ledger with zero new evals, which makes no sense for a study with no ledger at all. Requiring it unconditionally (BACKLOG #30) meant a pure-derivation study's strategizer could never satisfy Done() regardless of what its own tools/prompt said — this was the third of three places that assumption was baked in (the other two, the injected notebook_deliverable_spec() preamble and the notebook- authoring tools themselves, are already gated the same way). Additional paths can still be declared in state['required_deliverables'] regardless of this flag.
Source code in src/adda/_src/nodes/reproduction_gate.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 | |
_reproduction_gate(state: AgenticState | None = None) -> str | None
#
Before Done() can close a run — and on every RunNotebook(gate=True) dry run — pipeline.ipynb must satisfy every one of these, checked in order. This is a MECHANICAL check this exact function executes every time, not a judgement call, and nothing narrative or intent-based can satisfy it in a check's place.
- The canonical store must already hold at least one oracle row. Zero rows means no campaign has been evaluated yet, so there is nothing for the notebook to reproduce FROM — the gate refuses outright, before even running the notebook.
- The notebook must finish cleanly within a time ceiling (no heavy from-scratch computation — a reproduction is lazy, not a re-run).
- It must add ZERO new oracle rows: it may only LOAD the ledger
(
ExperimentData.from_file) and reach the oracle throughget_evaluator(), which skips every already-FINISHED row. - It must NOT modify or delete any existing ledger row — no faking a zero-delta by delete-then-re-add or by rewriting a value.
- The notebook prints a freshly-computed
REPRODUCED: <value>and theCLAIMED_HEADLINE: <value>its write-up states. The gate fails the notebook when the two differ. It does not fail a notebook for a missing print.
Passing (0)-(4) means the deliverable is a faithful, lightweight, lazy reproduction of a real, already-evaluated campaign — not a script doing something unrelated to validating the pipeline.
Source code in src/adda/_src/nodes/reproduction_gate.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 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 169 170 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 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | |
_halt_resumable(state: Any, *, reason: str, termination: str, status: str = 'halted', extra_update: dict | None = None)
#
Checkpoint-and-halt cleanly on an unrecoverable condition.
Instead of crashing, write debug/run_status.json (so tooling and
the human can see the run is resumable) and return a Command to
END whose last_report is prefixed with a HALTED banner. The
durable SqliteSaver checkpoint + the persisted thread_id are what
make the run resumable via AgenticRun(resume_from=...) — no new
serialized state is introduced here.
termination names WHICH unrecoverable condition fired. It is
carried on the state so the close path records it verbatim instead of
inferring an outcome from the HALTED banner — which matched none of the
old banner patterns and so read as GATED, logging every backstop kill
as a validated success.
Source code in src/adda/_src/nodes/lifecycle.py
17 18 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 46 47 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 | |
_halt_tallies(state: Any) -> dict
#
Source code in src/adda/_src/nodes/lifecycle.py
102 103 104 105 106 107 108 109 | |
_close_after_wind_down_error(state: Any, exc: Exception)
#
The turn that was to close a wind-down raised. The run closes anyway, with the halt's own termination, and says which retrospectives it lacks.
Source code in src/adda/_src/nodes/lifecycle.py
111 112 113 114 115 116 117 118 119 | |
_trip(state: Any, *, drift: dict, reason: str, termination: str, tallies: dict) -> Command | None
#
A backstop condition holds. Ask the run to wind down — every agent
gives its retrospective, the run closes with termination — instead of
jumping to END with none. While the wind-down is in progress this
returns None (the condition keeps holding; that is expected). Only a
wind-down that overruns its grace, or one that cannot be asked for,
falls through to the hard halt, so a halt is always bounded.
Source code in src/adda/_src/nodes/lifecycle.py
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 | |
_check_unrecoverable(state: Any, budget: float | None, start: float | None) -> Command | None
#
Return a halt Command if an unrecoverable condition is met, else None. Extracted verbatim from call (USD ceiling → repeated errors → time backstop).
Source code in src/adda/_src/nodes/lifecycle.py
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 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 238 239 240 241 242 243 244 245 246 247 248 249 | |
_find_critic_name() -> str | None
#
Name of the first connected critic worker, or None.
Source code in src/adda/_src/nodes/critic_gate.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
_prior_reviews_digest() -> str
#
A bounded <prior_reviews_this_run> block of THIS run's earlier
critic reviews (verdict + findings only), or "" if none.
The critic is invoked one-shot per gate with no live session and no RecallHistory, so without this it cannot see what it already ruled and can silently contradict an earlier verdict (the H1 SUPPORTED->FALSIFIED ->back whipsaw that drove the REVISE-spin). Echoing its standing objections back forces consistency: it may still reverse, but only by saying so and citing new evidence — never silently.
Source code in src/adda/_src/nodes/critic_gate.py
113 114 115 116 117 118 119 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 169 170 171 172 173 174 175 176 177 178 | |
_invoke_critic(task_msg: str) -> str
#
Synchronously invoke the connected critic; returns its text or an ERROR string.
The critic is a worker too: under runtime: debug its full transcript is
streamed to disk, its verdict/review is ALWAYS persisted (the PASS
branch doesn't echo it to the strategizer, so this is the only place
the deciding verdict is auditable), and its ### Retrospective is
recorded like every other node's (#7).
Source code in src/adda/_src/nodes/critic_gate.py
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 238 239 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 | |
_invoke_verdict_validator(prompt: str) -> str
#
One-shot LLM judgement reusing the CRITIC's adapter (same judge as the
gate), but lighter than _invoke_critic — it does NOT persist a critic
review or a retrospective. Records token usage so the call lands in the
run cost. Best-effort: returns "" if no critic is connected or the call
fails (the validator is advisory; a missing judge must not break the run).
Source code in src/adda/_src/nodes/critic_gate.py
280 281 282 283 284 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 322 323 | |
_cited_delegation_brief(evidence: dict | None) -> str | None
#
A short brief on the cited delegation — what it was asked to do and
whether it was flagged a falsification attempt — so the judge can weigh
§2 attempt-adequacy. The numeric result the verdict rests on is carried
separately in evidence['numbers']. None if no delegation is cited or
the record is absent.
Source code in src/adda/_src/nodes/critic_gate.py
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 | |
_run_verdict_validator(h_id: str, status: str, comment: str, evidence: dict | None) -> str
#
Advise (never block) on a closing verdict's substance against the
charter. Persists the critique on the verdict it judged, emits a
VERDICT_SUBSTANCE_FLAG diagnostics event on a flag, and on the Nth
repeat flag of the same hypothesis appends a louder gate-critic warning.
Returns the text to append to the HypothesisUpdate result ("" = no concern
/ validator unavailable). NEVER raises — the update it annotates must
always stand (Q1=(B), advise-with-teeth).
Source code in src/adda/_src/nodes/critic_gate.py
349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
_persist_critic_review(n: int, critique_text: str) -> str | None
#
Write the critic's full review to debug/critic_reviews/ so the deciding verdict is auditable regardless of PASS/REVISE. Best-effort. Returns the file name written (the caller's delegation row records it), or None when nothing was written.
Source code in src/adda/_src/nodes/critic_gate.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 | |
_build_feedback_task_msg(h_ids: list, *, constraints_text: str = '') -> str
#
constraints_text is the run's ConstraintSnapshot.as_text()
(see constraint_snapshot.py) — this is a delegation like any other
(strategizer -> critic), so it carries the same live budget facts
automatically, not something the critic has to go query for.
Source code in src/adda/_src/nodes/critic_gate.py
427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 | |
_role_of(target: str) -> str
#
Configured role of a connected node, falling back to its name.
Source code in src/adda/_src/nodes/recording.py
50 51 52 | |
_record_usage(usage: dict, *, role: str | None, model: str | None, phase: str | None, delegation_id: str | None) -> None
#
Accumulate token totals (decision path) AND emit one telemetry row
(additive, off the decision path). Telemetry failures are swallowed
inside record_call so they can never break a run.
Source code in src/adda/_src/nodes/recording.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 | |
_accumulate_usage(usage: dict) -> None
#
Thread-safe accumulation of token counts from adapter.last_usage.
Source code in src/adda/_src/nodes/recording.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |
_record_tool_error(node_name: str, tool_name: str, error_type: str, message: str, tb: str | None = None, args: dict | None = None) -> None
#
Increment error counter and append to diagnostics.jsonl (thread-safe).
args are the call's arguments; each value is capped at 2,000 chars.
Source code in src/adda/_src/nodes/recording.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | |
_record_llm_retry(attempt: int, max_attempts: int, exc: BaseException, delay: float) -> None
#
One diagnostics.jsonl row per transient-error retry of an LLM call.
Not an error (no _error_counts bump): the call is retried and may
succeed. The row exists so a retry is visible -- how often, which
exception, how long the backoff -- instead of silent.
Source code in src/adda/_src/nodes/recording.py
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 169 | |
_record_retrospective(role: str, source_id: str, report_text: str, deliverable_version: int | None = None) -> None
#
Capture a node's end-of-life ### Retrospective.
Every node has a 'my job is done' moment — workers at delegation completion, the strategizer (and any future orchestrator) at Done(). Parse the section, persist to retrospectives.jsonl, and surface a diagnostic + strategizer notification the instant it flags contradictory system instructions (the cheapest, highest-value failure mode to catch). Best-effort; never raises.
A Done() call that ACTUALLY ARRIVED with non-empty text is always
recorded here, even when _extract_report_section fails to find
a ### Retrospective heading in it — never silently dropped. Only
genuinely empty text (nothing submitted at all) returns without
writing anything. This matters because write_fallback_retrospective
(infra/watchdog_cleanup.py) trusts "no entry for this role in
retrospectives.jsonl" to mean "the retrospective never arrived" and
synthesizes a claim saying so; if a real, substantive reply arrived
but merely failed to parse (run 20260926T124841's regex bug, now
fixed — see _extract_report_section), silently dropping it here made
that downstream claim FALSE — the run's own record said a retrospective
"never arrived" when one, in fact, had. Recording a parse-failure
entry (with the raw text preserved) keeps that claim honest without
needing write_fallback_retrospective itself to know the difference.
Source code in src/adda/_src/nodes/recording.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 238 239 240 241 242 243 244 245 246 247 | |
_record_intervention(kind: str, target: str, message: str, *, fault: str = 'nudge', **extra) -> None
#
Log a scientific-correction event (a nudge/bounce firing) to
diagnostics.jsonl — direct evidence the self-healing layer acted,
and, when extra carries before/after state, whether it worked.
Neutral classification: fault='nudge' — a nudge is a correction, not
an agent error, so this must NOT bump the error/escalation counters
(unlike _record_tool_error). fault='observation' is for a row that
only records what was seen (adda said nothing to the agent); it also
bumps no counter. Best-effort; never raises.
Source code in src/adda/_src/nodes/recording.py
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 283 | |
_record_science_drift(payload: dict) -> None
#
Append a SCIENCE_DRIFT record to diagnostics.jsonl.
Source code in src/adda/_src/nodes/recording.py
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 | |
_raise_if_abandoned() -> None
#
End the calling thread once the run has stopped waiting for it.
Source code in src/adda/_src/nodes/node.py
147 148 149 150 151 | |
_init_recording() -> None
#
Establish the state RecordingMixin writes to, on EVERY node.
Recording is a property of a node — any node's tools can return an
ERROR, and any node's adapter reports token usage — so its substrate
belongs here rather than in one behaviour's setup. It used to be
created only by the orchestration setup, which was invisible while
leaves were a separate class that did not carry RecordingMixin at all:
the moment a leaf reached any recording call it raised AttributeError
on _registry_lock. The orchestration setup still assigns these
itself, to the same values, so an orchestrating node is unchanged.
Source code in src/adda/_src/nodes/node.py
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
_init_capabilities(*, study_dir: Any = None, workspace_dir: Any = None, delegation_log: DelegationLog | None = None, report_sections: tuple[str, ...] | None = None, agent_tools: frozenset[str] | None = None) -> None
#
Wire this node's sandboxed Write and its declared read-only tools.
Runs for EVERY node, not only one reachable as a standalone entry
point — see the module docstring: whichever node ends up as someone
else's Delegate() target is dispatched through a copy of THIS adapter
(adapter.copy() carries the closure_tools set here), so this is where a
dispatched specialist's baseline capabilities actually come from,
before WorkerSession.install_worker_tools/_sandbox_worker_writes
layer the per-delegation overrides (ReportEvals's own record callback,
a delegation-scoped Write) on top.
Source code in src/adda/_src/nodes/node.py
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 238 239 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 | |
_setup_sandboxed_write() -> None
#
Replace native Write with a workspace-sandboxed closure.
Removes 'Write' from native_tools so the SDK doesn't expose it,
then installs the same builder a dispatched worker gets
(:func:build_sandboxed_write), scoped to this node's whole
workspace instead of one delegation's subfolder — a node reached via
real graph routing (the module docstring) has no delegation_id of
its own to scope tighter than that.
Bash is kept native but cwd is already set to study_dir by the adapter; the prompt further constrains it to the workspace.
Source code in src/adda/_src/nodes/node.py
266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 | |
_build_eval_closures() -> dict
#
Source code in src/adda/_src/nodes/node.py
303 304 305 306 307 308 309 310 311 | |
_commit_workspace(message: str) -> str | None
#
Commit the run workspace and return the sha (spec 11).
On Node rather than on WorkerSession because a delegation is recorded
from four places, not one: a worker finishing (ok or error), the
critic gate, an AskForFeedback audit, and the close-time
reconciliation of a delegation still running when the run ended. Every
one of them appends a row to the delegation log, so every one of them
owes that row a sha — otherwise workspace_sha: null means both
"this delegation changed nothing" and "nobody looked", which is the
ambiguity --allow-empty exists to prevent.
The interrupted case is the one with teeth: a delegation killed mid-flight never reaches _finish_ok/_finish_error, so its partial file writes stay uncommitted and are swept into whichever delegation commits NEXT — attributing one delegation's work to another. Silence would be better than that; a commit is better still.
Never raises — see infra/workspace_vcs.
Source code in src/adda/_src/nodes/node.py
318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 | |
_resolve_run_dir() -> Path | None
#
Best-effort run_dir, valid on any node.
Every node's _current_notes_dir is set at construction (from
notes_dir, passed to every node — see graph_builder.py) and
re-pointed each turn by _absorb_state if the run's real notes dir
differs. It can still be None (e.g. a bare Node() built
without one, as in unit tests) — every node DOES hold the shared
delegation log at run_dir/debug/delegation_log.jsonl, so derive
run_dir from that when the notes dir is unavailable.
Source code in src/adda/_src/nodes/node.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | |
_read_ledger() -> HypothesisLedger | None
#
The hypothesis ledger for READ access, resolved on any node.
Returns the node's own bound ledger when it has one (the entry node); otherwise resolves a read-only view from the run's strategizer_notes when hypotheses.json exists. HypothesisLedger.init performs no I/O, and only READ callers use this, so there is no write race with the entry node that owns the file.
Source code in src/adda/_src/nodes/node.py
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 | |
adda.build_graph(spec: Graph, make_adapter: Callable[[str, Agent], Any], checkpointer: Any = None, study_dir: Any = None, interactive: bool = False, max_ask: int = 1, notes_dir: Any = None, workspace_dir: Any = None, delegation_log: DelegationLog | None = None, node_registry: dict[str, Any] | None = None) -> Any
#
Build and compile a LangGraph StateGraph from a Graph spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
Graph
|
Agent graph specification (nodes, edges, entry). |
required |
make_adapter
|
callable
|
|
required |
checkpointer
|
any
|
LangGraph checkpointer. Defaults to an in-memory :class: |
None
|
delegation_log
|
DelegationLog
|
Graph-wide delegation log for episodic memory (RecallHistory tool). |
None
|
node_registry
|
dict
|
If given, populated in place with |
None
|
Returns:
| Type | Description |
|---|---|
CompiledGraph
|
A compiled LangGraph graph ready to invoke. |
Source code in src/adda/_src/runtime/graph_builder.py
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 46 47 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 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Run state#
The types that move through the graph while it runs. You rarely construct these yourself; they are what you see in a transcript or a checkpoint.
adda.AgenticState
#
LangGraph state for one agentic run.
Inherits messages: Annotated[list[AnyMessage], add_messages]
from :class:~langgraph.graph.MessagesState.
Source code in src/adda/_src/runtime/graph_state.py
10 11 12 13 14 15 16 17 18 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 | |
study_dir: str
instance-attribute
#
done: bool
instance-attribute
#
last_report: str | None
instance-attribute
#
total_delegations: int
instance-attribute
#
budget_seconds: float | None
instance-attribute
#
budget_usd: float | None
instance-attribute
#
run_dir: str | None
instance-attribute
#
eval_budget: int | None
instance-attribute
#
evals_used: int
instance-attribute
#
start_time: float | None
instance-attribute
#
required_deliverables: list | None
instance-attribute
#
token_totals: dict | None
instance-attribute
#
error_counts: dict | None
instance-attribute
#
experiment_data_dir: str | None
instance-attribute
#
outcome: str | None
instance-attribute
#
termination: str | None
instance-attribute
#
reviewed: bool | None
instance-attribute
#
adda.StudyConfig
dataclass
#
Lightweight config loaded from the study directory.
Source code in src/adda/_src/runtime/graph_state.py
82 83 84 85 86 87 88 | |
adda.Task
dataclass
#
A unit of work delegated from one agent to another.
Source code in src/adda/_src/runtime/graph_state.py
52 53 54 55 56 57 58 | |
adda.Report
dataclass
#
The result returned by an implementer agent.
Source code in src/adda/_src/runtime/graph_state.py
61 62 63 64 65 66 | |
adda.Delegation
dataclass
#
A delegation request parsed from an agent's response.
Source code in src/adda/_src/runtime/graph_state.py
69 70 71 72 73 74 75 76 77 78 79 | |