# provideAgent

Package: `@threadplane/ag-ui` · 0.3.4

Reference: /docs/api/ag-ui/provideAgent

```typescript
import { provideAgent } from '@threadplane/ag-ui';
```

## provideAgent · overload 1

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.

```typescript
export declare function provideAgent<T = Record<string, unknown>>(ref: AgentRef<T>, configOrFactory: AgentConfig | (() => AgentConfig)): Provider[];
```

Typed state via AgentRef
```ts
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>
```

## provideAgent · overload 2

```typescript
export declare function provideAgent(configOrFactory: AgentConfig | (() => AgentConfig)): Provider[];
```