Documentation Index
Fetch the complete documentation index at: https://docs.trodo.ai/docs/llms.txt
Use this file to discover all available pages before exploring further.
What / When / Minimum
When your agent is spread across multiple files (a triage function that calls a researcher that calls a writer), you don’t pass therunId between them. The SDK uses Node’s AsyncLocalStorage (Python’s contextvars) to propagate the active run context through every async call — import withSpan in any file and it attaches to the current run automatically.
Minimum: one wrapAgent at the entry point. Every nested file calls trodo.withSpan(...) directly.
The pattern
triage, researcher, writer lives in its own file and calls trodo.withSpan(...) for whatever sub-steps it owns. None of them receives a runId; none of them imports anything from the entry file.
triage.js
researcher.js
writer.js
index.js
pipeline → triage (agent) → research (retrieval) → write (llm).
Python equivalent
contextvars are propagated automatically across await, threads (via copy_context), and asyncio.create_task. Same pattern:
Checking the current context
Need to know mid-code whether you’re inside a run?withSpan is a no-op. That means your library code can call trodo.withSpan(...) unconditionally — when invoked standalone it emits nothing, when invoked inside a wrapAgent it joins the tree.
Running sub-steps in parallel
wrapAgent root) and render side-by-side in the waterfall. AsyncLocalStorage handles the branching automatically.
Gotchas
- Callbacks outside the async chain break context.
setImmediate,setTimeout,EventEmitterlisteners scheduled beforewrapAgentopened may run outside the context. Fix: schedule them inside. - Worker threads and child processes don’t share context. Use cross-service propagation or explicit
joinRun. - Queue workers (BullMQ, SQS, RabbitMQ). The consumer runs in a fresh event loop tick; open a new
wrapAgentper job and passrunIdon the job payload if you need to link it to the producer. See sub-agents forparent_run_id. - Top-level
awaitin a module that runs beforetrodo.initraces the processor. Callinitfirst, synchronously.