feat(ag-ui): scriptable provideFakeAgent() and a duplicate-AgentRef warning - #1053
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
…ctor The ref form of provideAgent() aliases the shared AGENT token, so N refs at one injector level leave the ref-less injectAgent() pointing at the Nth with no signal. Each ref-form call now also contributes its debug name to an internal multi token; the first agent built at that level reads the list and, in development mode only, emits a single console.warn naming every ref and the one the bare injectAgent() resolves. Multi providers do not merge across injectors, so refs at different levels neither collide nor warn. Behavior is otherwise unchanged: each ref still gets its own agent and its own config evaluation. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
FakeAgent's script option was constructor-only and unreachable through provideFakeAgent(), which accepted the shared FakeAgentConfig from @threadplane/chat/testing (tokens, reasoningTokens, delayMs). provideFakeAgent() now takes AgUiFakeAgentConfig — that shared config plus the AG-UI-only script — and passes it to the constructor, so tool calls, state, custom events, and interrupts are all scriptable through DI. The script shape is exported as FakeAgentScript. The shared config type in libs/chat is untouched. Docs updated: the api and guide pages no longer say script is constructor-only or that provideFakeAgent() cannot emit TOOL_CALL_*, STATE_* or CUSTOM, and each carries a fence that runs. api-docs regenerated. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
blove
force-pushed
the
blove/ag-ui-fake-agent-script
branch
from
September 7, 2026 21:47
dd34e91 to
5a81590
Compare
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes two AG-UI library follow-ups.
1. Development warning when several
AgentRefs share an injectorThe ref form of
provideAgent(ref, …)aliases the sharedAGENTtoken, so N refs registered at one injector level leave the ref-lessinjectAgent()pointing at the Nth with no signal at all.Each ref-form call now also contributes its debug name to an internal multi token. The first agent built at that level reads that list and, under
isDevMode()only, emits a singleconsole.warnnaming every ref registered there and the one the bareinjectAgent()resolves. Multi providers do not merge across injectors, so refs at different levels (application config vs. a component'sproviders) neither collide nor warn. Nothing about resolution changes: each ref still gets its own agent and its own config evaluation.2.
provideFakeAgent()acceptsscriptFakeAgent'sscriptoption was constructor-only and unreachable throughprovideFakeAgent(), which took the sharedFakeAgentConfigfrom@threadplane/chat/testing(tokens/reasoningTokens/delayMs). It now takesAgUiFakeAgentConfig— that shared config plus the AG-UI-onlyscript— and forwards it to the constructor, so tool calls, shared state, custom events, and interrupts are all scriptable through DI. The script shape is exported asFakeAgentScript. The shared config type inlibs/chatis untouched.Also confirmed while here:
FakeAgentdoes wrap a scripted batch inRUN_STARTED/RUN_FINISHEDas the docs claim (existing spec), and the{ toolMessageFor }branch does fire on the follow-up run — a new spec drives that through the real path,clientTools.resolve()adding the tool message and starting the continuation.Specs
libs/ag-ui/src/lib/provide-agent.duplicate-ref-warning.spec.ts(new): two refs at one level warn exactly once, the message names both refs, both agents stay distinct, the bare token still resolves the last one; a single ref does not warn; refs at different injector levels do not warn. Failed before the change (0 warnings), passes after.libs/ag-ui/src/lib/testing/provide-fake-agent.spec.ts:provideFakeAgent({ script })reduces a scripted tool call intotoolCalls(), state and custom events intostate()/customEvents(), aCUSTOMon_interruptintointerrupt(), and runs the{ toolMessageFor }branch on the continuation thatclientTools.resolve()starts.libs/ag-ui/src/lib/testing/provide-fake-agent.type-spec.ts(new): thescriptproperty is part of the accepted config. This is the compile-level guard — the runtime already passed the property through structurally, and the old signature was what rejected it. Verified failing before the change withTS2353: 'script' does not exist in type 'FakeAgentConfig'.Docs
ag-ui/api/provide-agent.mdxandag-ui/concepts/architecture.mdx: the last-ref-wins rule now also describes the development warning, with the message text.ag-ui/api/fake-agent.mdx,ag-ui/guides/fake-agent.mdx,ag-ui/guides/testing.mdx: no longer sayscriptis constructor-only or thatprovideFakeAgent()cannot emitTOOL_CALL_*,STATE_*, orCUSTOM. Each carries a fence that was run as a spec before being pasted in.apps/website/content/docs/ag-ui/api/api-docs.jsonregenerated.Verification
npx nx run-many -t lint,test,build --projects=ag-ui— green (0 lint errors, 275 tests in 14 files).npx vitest run --root apps/website— 1326 tests in 131 files, green.GROWTH_FORM_POLICY=growth_v1 npx nx build website— green.Note:
nx run ag-ui:type-testsis red onorigin/mainin this environment for reasons unrelated to this branch (TS5101on the config's deprecatedbaseUrl, plusTS6059rootDir errors on every cross-library import). The new type-spec was checked withtsc --ignoreDeprecations 6.0and reports no errors of its own.🤖 Generated with Claude Code