import { MessageJSON } from "smoltalk"; import type { AgencyCallbacks } from "./hooks.js"; import type { RuntimeContext } from "./state/context.js"; import type { AgencyFunction } from "./agencyFunction.js"; import { State, StateStack } from "./state/stateStack.js"; import { ThreadStore } from "./state/threadStore.js"; import { GraphState, RunNodeResult } from "./types.js"; export declare function setupNode(args: { state: GraphState; }): { stack: State; step: number; self: Record; threads: ThreadStore; }; export declare function setupFunction(): { stateStack: StateStack; stack: State; step: number; self: Record; threads: ThreadStore; }; /** * Invoke an exported Agency function from *outside* any Agency execution * frame — the `agency serve` path, where an HTTP/MCP request maps a * function name + named args to a single stateless call. * * Generated function bodies assume an ambient `agencyStore` frame: they * read `getRuntimeContext().ctx`, the base `StateStack`/`ThreadStore` via * `setupFunction()`, and globals via `__globals()`. In normal execution a * function only ever runs inside a node body (or an LLM tool-call that is * itself inside a node), so that frame is already installed. `runNode` * installs it for nodes; this is the equivalent entry point for a bare * function call. Without it the first line of every generated function * throws "getRuntimeContext() called outside an Agency execution frame". * * Mirrors `runNode`'s bootstrap (cross-module init, this module's globals * init, top-level callback registration) against a fresh execution * context so the function sees fully-initialized statics/globals and any * module-level `callback(...)` blocks, then runs the call inside a * node-grade ALS frame with a real `ThreadStore` (so functions that use * `llm()` / message threads work), and tears it down like `runNode` does * (persist memory, flush statelog). * * Two deliberate divergences from `runNode`, both consequences of the * stateless-RPC model: * - No `agentStart`/`agentEnd` span and no run-level token roll-up. The * generated function body still reports its own failures to statelog * and converts exceptions to a `Failure` result, so per-call errors * are traced and surface to the caller; what is absent is only the * run-level envelope. A practical consequence: `llm()` spend inside a * served function is not attributed to `getCost` / cost dashboards. * - No checkpoint/restore loop — a function call is one shot, so there * is no `RestoreSignal` handling here (a `catch` would risk swallowing * that and other control-flow signals). */ export declare function runExportedFunction({ ctx, fn, namedArgs, initializeGlobals, }: { ctx: RuntimeContext; fn: AgencyFunction; namedArgs: Record; initializeGlobals?: (ctx: RuntimeContext) => void | Promise; }): Promise; export declare function runNode({ ctx, nodeName, data, messages, callbacks, initializeGlobals, abortSignal, }: { ctx: RuntimeContext; nodeName: string; data: Record; messages?: MessageJSON[]; callbacks?: AgencyCallbacks; initializeGlobals?: (ctx: RuntimeContext) => void | Promise; abortSignal?: AbortSignal; }): Promise>;