# ctx.agents `AgentRegistry` — provided by `@deepseek-ai/dsh-agent`. Agent registry (`ctx.agents`): tracks live agents so UI, hook, and orchestrator plugins can find them without depending on the concrete loop package. Agent *creation* is provided by whichever plugin implements the AgentFactory (phase 1: `@deepseek-ai/dsh-agent-loop`), registered via setFactory. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L117) ### ctx.agents.setFactory(factory) ```ts website-api setFactory(factory: AgentFactory): () => void ``` Register the agent-creation factory (the loop calls this on construction, effect-scoped). Throws if a factory is already registered. Returns the disposer; on dispose the factory slot is cleared. - `factory` — the loop-owned factory {@link create}/{@link resume} delegate to. **Returns** the disposer that clears the factory slot. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L132) ### ctx.agents.create(options) ```ts website-api create(options: CreateAgentOptions): AgentHandle ``` Create, start, and register a new agent through the registered factory. Distinct from register (which records an already-constructed agent): this constructs the agent and its session. Throws if no factory is registered. Returns an AgentHandle — the owner disposes it to tear down exactly this agent. - `options` — agent id, session id/seed/metadata, and agent options. **Returns** the handle whose dispose tears down exactly this agent. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L150) ### ctx.agents.resume(options) ```ts website-api async resume(options: ResumeAgentOptions): Promise ``` Load a persisted session and resume an agent on it through the registered factory. Rejects if no factory is registered; the factory rejects if session persistence is not configured. Returns an AgentHandle. - `options` — the persisted session id plus agent id and options. **Returns** the handle for the resumed agent. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L162) ### ctx.agents.register(agent) ```ts website-api register(agent: Agent): () => void ``` Register a live agent. Throws if an agent with the same id is already registered. Emits `agent/created` on registration and `agent/disposed` when the calling fiber is disposed. Returns the disposer. - `agent` — the already-constructed agent to record in the store. **Returns** the disposer that removes the agent and emits `agent/disposed`. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L174) ### ctx.agents.get(id) ```ts website-api get(id: AgentId): Agent | undefined ``` Look up a live agent. - `id` — the agent id to look up. **Returns** the agent, or undefined when no live agent has that id. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L216) ### ctx.agents.list() ```ts website-api list(): Agent[] ``` All live agents, in registration order. **Returns** a fresh array; mutating it does not affect the registry. [Source](https://github.com/deepseek-harness/deepseek-harness/blob/master/packages/core/agent/src/index.ts#L224)