FakeAgent
FakeAgent is an in-process AG-UI test double that emits a canned streaming response without a real backend. Use it for offline development, CI, and component tests.
provideFakeAgent()
provideFakeAgent() is the DI-friendly entry point. It is a drop-in replacement for provideAgent({ url }) when no backend is available.
import { bootstrapApplication } from '@angular/platform-browser';
import { provideFakeAgent } from '@threadplane/ag-ui';
import { AppComponent } from './app/app.component';
bootstrapApplication(AppComponent, {
providers: [
provideFakeAgent(),
],
});Pass a FakeAgentConfig to customize the canned response:
provideFakeAgent({
tokens: ['Hello', ' world', '!'],
delayMs: 40,
})FakeAgentConfig
| Option | Type | Description |
|---|---|---|
tokens | string[] | Assistant reply streamed token-by-token. Defaults to a fixed placeholder message. |
reasoningTokens | string[] | Optional reasoning chunks emitted before the text reply. |
delayMs | number | Milliseconds between successive token emissions. Defaults to 60. |
FakeAgent class
Construct a FakeAgent directly when you need lower-level control, for example to pass it to toAgent() in a test harness.
import { FakeAgent } from '@threadplane/ag-ui';
import { toAgent } from '@threadplane/ag-ui';
const agent = toAgent(new FakeAgent({
tokens: ['Thinking', '...', ' done.'],
reasoningTokens: ['Step 1', ': evaluate'],
delayMs: 30,
}));FakeAgent extends AbstractAgent from @ag-ui/client. Its run() method returns an Observable<BaseEvent> that emits the full event sequence — RUN_STARTED, optional reasoning events, TEXT_MESSAGE_START / TEXT_MESSAGE_CONTENT tokens, TEXT_MESSAGE_END, RUN_FINISHED — then completes.
TestBed example
import { TestBed } from '@angular/core/testing';
import { provideFakeAgent, injectAgent } from '@threadplane/ag-ui';
import { Component } from '@angular/core';
@Component({ template: '' })
class ChatComponent {
readonly chat = injectAgent();
}
describe('ChatComponent', () => {
beforeEach(() => {
TestBed.configureTestingModule({
imports: [ChatComponent],
providers: [
provideFakeAgent({ tokens: ['Hello', ' from', ' fake'] }),
],
});
});
it('streams a canned reply', async () => {
const fixture = TestBed.createComponent(ChatComponent);
fixture.detectChanges();
await fixture.componentInstance.chat.submit({ message: 'Hi' });
fixture.detectChanges();
expect(fixture.componentInstance.chat.messages().at(-1)?.content)
.toBe('Hello from fake');
});
});FakeAgent and provideFakeAgent() are intended for development and tests
only. Do not use them in production builds.
See also: Fake Agent guide for practical offline-development patterns, and Testing guide for full component-testing recipes.