provideAgent
Provides one Agent, built from a session factory. Retrieve it in any
component with injectAgent(). Provide it at the application root for an
app-wide agent, or in a component's providers to give that subtree its
own.
The agent creates its sessions through config.createSession, so this
package depends on no backend. The last session is disposed when the
providing injector is destroyed.
Static or factory config. Pass the config object when it is known up
front. Pass a () => AgentConfig factory when it depends on injected state:
the factory runs once, in an injection context, so it may call inject().
Typed agents. Pass an AgentRef first to carry the session type
from provideAgent to injectAgent(ref).
Several agents at one injector level. Each provideAgent(ref, …) call
builds its own agent from its own config, so several refs may share one
providers array and injectAgent(refA) / injectAgent(refB) return
distinct agents. The ref-less injectAgent() resolves one shared token,
which can name only one of them: the last call wins, and resolving it in
development mode logs a console.warn naming every competing ref.
AGENT_LIFECYCLE follows the same rule.
import { provideAgent } from '@threadplane/angular';Declaration · overload 1
export declare function provideAgent<TSession extends AgentSessionLike>(ref: AgentRef<TSession>, config: AgentConfigInput<NoInfer<TSession>>): Provider[];Type parameters
TSessionAgentSessionLike
Parameters
ref· requiredAgentRef<TSession>config· requiredAgentConfigInput<NoInfer<TSession>>
Returns
Provider[]Examples
providers: [
provideAgent({
threadId: currentThreadId,
createSession: (context) =>
createSession({ assistantId: 'chat', apiUrl, ...context }),
}),
];Declaration · overload 2
export declare function provideAgent<TSession extends AgentSessionLike>(config: AgentConfigInput<TSession>): Provider[];Type parameters
TSessionAgentSessionLike
Parameters
config· requiredAgentConfigInput<TSession>
Returns
Provider[]