agentfootprint
Version:
The explainable agent framework — backtrack a wrong answer to the exact context that caused it (evidence, not guesses). Built on footprintjs.
57 lines (56 loc) • 2.98 kB
TypeScript
/**
* buildDynamicAgentChart — the Dynamic-ReAct agent chart, where the
* whole LLM turn (context engineering + the call) is ONE `sf-llm-call`
* subflow, exactly like the `LLMCall` primitive produces.
*
* WHY a second builder (vs `buildAgentChart`)
* ───────────────────────────────────────────
* `buildAgentChart` mounts the LLM as a flat `call-llm` STAGE with the
* slot subflows as its siblings. That renders as nothing in Lens — a
* bare stage is dropped by the subflow-level collapser, so the slots
* have no LLM card to fold into and the chart comes up empty.
*
* This builder wraps that same region in an `sf-llm-call` SUBFLOW. The
* payoff is purely structural — Lens already maps `sf-llm-call → LLM
* group` (same boundary `LLMCall` produces), so the Dynamic agent
* renders as an LLM group with its slots inside, a peer Tool node, and
* the loop arc, with ZERO Lens-specific special-casing.
*
* The data flow is IDENTICAL to `buildAgentChart` — every stage handler
* + slot subflow is reused verbatim from the same `AgentChartDeps`. The
* ONLY new thing is the subflow boundary, which means:
*
* • A small inner seed (`dynamicTurnSeed`) initialises the per-turn
* working keys the OUTER seed used to set, since the inner subflow
* gets a fresh scope each loop re-entry.
* • Cross-iteration accumulators (token totals, cost counters,
* skill-history) round-trip out→in: the boundary `outputMapper`
* bubbles them to the outer scope, and the next iteration's
* `inputMapper` feeds them back under `prior*` aliases (because
* keys passed via `inputMapper` are FROZEN inside the subflow —
* `ScopeFacade.setValue` throws on them — so the writable working
* key must have a different name from the read-only input).
*
* Chart shape (mirrors the diagram the team locked):
*
* Initialize
* → [memory READ subflows]
* → sf-llm-call (SUBFLOW — same boundary LLMCall produces)
* dynamicTurnSeed → InjectionEngine
* → Context (selector, PARALLEL fan-out, failFast)
* ⇉ {System Prompt ‖ Messages ‖ Tools} → converge
* → UpdateSkillHistory → Cache (sf-cache subflow)
* → CallLLM (emits iteration_start) → [NormalizeThinking]
* → Route (decider)
* ├─ tool-calls (pausable) → loopTo(sf-llm-call) ← branch-sourced loop
* └─ sf-final (the answer) → terminal leaf
*
* Classic ReAct keeps using `buildAgentChart` until its own shape is
* designed — this builder is Dynamic-only.
*/
import type { FlowChart } from 'footprintjs';
import { type AgentChartDeps } from './buildAgentChart.js';
/**
* Build the Dynamic-ReAct agent chart from the shared `AgentChartDeps`.
*/
export declare function buildDynamicAgentChart(deps: AgentChartDeps): FlowChart;