provideAgent()

provideAgent() registers the singleton agent configuration for every injectAgent() call in an Angular application. Call it once in bootstrapApplication or an ApplicationConfig to wire up the LangGraph API URL, assistant id, thread persistence, and transport.

injectAgent() itself takes no arguments โ€” all configuration flows through provideAgent().

import { bootstrapApplication } from '@angular/platform-browser';
import {
  provideAgent,
  MockAgentTransport,
} from '@threadplane/langgraph';
import { AppComponent } from './app/app.component';
 
bootstrapApplication(AppComponent, {
  providers: [
    provideAgent({
      apiUrl: 'http://localhost:2024',
      assistantId: 'my-agent',
      transport: environment.testMode
        ? new MockAgentTransport()
        : undefined,
    }),
  ],
});

#Configuration options

OptionTypeDescription
apiUrlstringLangGraph Platform API base URL.
assistantIdstringLangGraph assistant id to bind to.
threadId() => string | undefinedOptional thread id provider, used to resume a persisted thread.
onThreadId(id: string) => voidOptional callback fired when a new thread id is assigned.
transportAgentTransportOptional transport instance. Defaults to FetchStreamTransport when omitted.

#Singleton model

A single provideAgent({...}) call configures the entire application. Every injectAgent() call resolves to the same configured agent.

provideAgent({
  apiUrl: 'https://api.example.com',
  assistantId: 'support-agent',
});
 
// Elsewhere, inside an injection context:
const chat = injectAgent();

#Test transports

transport is an object that implements AgentTransport, not an Angular class token. Create an instance before passing it to provideAgent().

const transport = new MockAgentTransport();
 
TestBed.configureTestingModule({
  providers: [
    provideAgent({
      apiUrl: '',
      assistantId: 'test-agent',
      transport,
    }),
  ],
});
Test transports

Swap out the live transport for MockAgentTransport in tests by changing only the transport field on provideAgent(). injectAgent() call sites stay unchanged across environments.

#What's Next

provideAgentfunction

Wire the LangGraph adapter into Angular's dependency injection. Registers a singleton `LangGraphAgent` constructed from `config`. Retrieve it in any component with `injectAgent()`. Provide this at the application root (`app.config.ts`) for an app-wide agent. To use a different agent in a component subtree, re-provide `provideAgent({...})` in that component's `providers: []` array โ€” Angular's hierarchical DI scopes the singleton accordingly. **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, route params, or component-scoped signals: ```ts providers: [ provideAgent(() => { const route = inject(ActivatedRoute); return { assistantId: 'chat', threadId: toSignal(route.paramMap) }; }), ]; ```

provideAgent(configOrFactory: AgentConfig<T, BagTemplate> | object): Provider[]

Parameters

ParameterTypeDescription
configOrFactoryAgentConfig<T, BagTemplate> | object

Returns

Provider[]