provideAgent
Provides an Agent instance wired through HttpAgent and toAgent. Constructs an HttpAgent from config and wraps it in the runtime-neutral Agent contract via toAgent(). Returns a provider array suitable for bootstrapApplication or TestBed.configureTestingModule().
Static vs factory config. Pass a plain AgentConfig object when the
config is known up front. Pass a () => AgentConfig factory when the config
depends on runtime/DI state — the factory runs inside an Angular injection
context, so it may call inject() to read services or route params.
Typed state via AgentRef. Pass a typed ref as the first argument to flow
the state shape from provideAgent to injectAgent without repeating the
generic at every call site.
Several agents at one injector level. Each provideAgent(ref, …) call
builds its own agent, so two (or more) refs may be provided side by side in a
single providers array and injectAgent(refA) / injectAgent(refB) return
distinct agents. The ref-less injectAgent() resolves a single shared token,
which can only point at one of them: when more than one ref is provided at
the same level the last call wins. Always inject by ref when an injector
provides more than one agent. Development builds emit a one-time
console.warn naming the refs involved when an injector level registers more
than one, so the silent last-ref-wins aliasing is visible during development.
import { provideAgent } from '@threadplane/ag-ui';Declaration · overload 1
export declare function provideAgent<T = Record<string, unknown>>(ref: AgentRef<T>, configOrFactory: AgentConfig | (() => AgentConfig)): Provider[];Type parameters
TDefault:Record<string, unknown>
Parameters
ref· requiredAgentRef<T>configOrFactory· requiredAgentConfig | (() => AgentConfig)
Returns
Provider[]Examples
Typed state via AgentRef
interface TripState { day: number; places: string[]; }
export const TRIP = createAgentRef<TripState>('trip');
// app.config.ts:
providers: [provideAgent(TRIP, { url: 'http://localhost:8000/agent' })]
// component:
const agent = injectAgent(TRIP); // AgUiAgent<TripState>Declaration · overload 2
export declare function provideAgent(configOrFactory: AgentConfig | (() => AgentConfig)): Provider[];Parameters
configOrFactory· requiredAgentConfig | (() => AgentConfig)
Returns
Provider[]