# Self-managed agents

> Connect AG-UI agents that you host and secure yourself.

If you host and secure your own AG-UI agent, the frontend can call it directly,
without the CopilotKit [runtime](/llamaindex/backend/copilot-runtime). Use
`selfManagedAgents` in production. For local development, use
`agents__unsafe_dev_only` in React or `agents` in Angular.

## Production: self-managed agents [#production-self-managed-agents]

`selfManagedAgents` is the supported configuration option for connecting agents you manage
yourself, for example an [`HttpAgent`](/llamaindex/backend/ag-ui) pointing at an
AG-UI-compatible backend you own and have already secured:

```tsx
import { HttpAgent } from "@ag-ui/client";
import { CopilotKit } from "@copilotkit/react-core/v2";

const supportAgent = new HttpAgent({
  url: "https://agents.example.com/support",
});

<CopilotKit
  selfManagedAgents={{ "support-agent": supportAgent }}
>
  <YourApp />
</CopilotKit>;
```

Each key is the `agentId` that chat components and frontend agent APIs use to
address that agent. Self-managed agents use your transport and your security
model. Because the requests don't pass through the CopilotKit runtime, the
runtime's server-side auth, middleware, and routing do not apply. Your agent
endpoint must [authenticate and authorize every request](/llamaindex/auth).

Open a chat that uses the `support-agent` agent ID and send a message. The
endpoint at `https://agents.example.com/support` receives the run, and its reply
streams into the chat.

<Callout type="info" title="Part of CopilotKit Intelligence">
  `selfManagedAgents` is part of the CopilotKit Intelligence [Enterprise
  plan](/llamaindex/intelligence/intelligence-platform). [Talk to an
  engineer](https://copilotkit.ai/talk-to-an-engineer) about licensing for
  production use.
</Callout>

<Callout type="info">
You can combine `selfManagedAgents` with `runtimeUrl`. Runtime-discovered agents
and self-managed agents coexist; address each by its `agentId`.
</Callout>

## Development: local agents [#development-local-agents]

`agents__unsafe_dev_only` accepts the same shape: a map of `agentId` to
`AbstractAgent`. The name is intentionally loud. Use it only for local
development and prototyping.

```tsx
import { HttpAgent } from "@ag-ui/client";
import { CopilotKit } from "@copilotkit/react-core/v2";

const myAgent = new HttpAgent({ url: "http://localhost:8000" });

<CopilotKit agents__unsafe_dev_only={{ "my-agent": myAgent }}>
  <YourApp />
</CopilotKit>;
```

Use it when you connect an agent on your own machine and do not have a runtime
yet. Don't ship it to production. Switch to `selfManagedAgents` if you
intend to manage and secure the connection yourself, or move the agent behind the
[runtime](/llamaindex/backend/copilot-runtime).

## How they relate [#how-they-relate]

Both sources feed the same client-side agent registry. When both are supplied
they are merged, and **`selfManagedAgents` wins on a key collision**:

```ts
// effective agents ≈ { ...agents__unsafe_dev_only, ...selfManagedAgents }
```

If at least one agent is registered through either provider option, the
frontend configuration check passes.

You won't get the
`Missing required prop: 'runtimeUrl' or 'publicApiKey' or 'publicLicenseKey'`
error; see the [error reference](/llamaindex/troubleshooting/error-reference).

| | `selfManagedAgents` | Local agents |
|---|---|---|
| **Intended for** | Production, agents you manage | Local dev / prototyping |
| **Auth** | Your responsibility | Your responsibility |
| **Runtime middleware / routing** | Not applied | Not applied |
| **Precedence on collision** | Wins | Overridden by `selfManagedAgents` |
