Stored Agent Definitions
Stored agent definitions are agents a hosted application creates while it runs, beside the code agents registered on the runtime. A runtime route agentId must resolve to a code agent (an agent the recipe adds with AddAgent(...) or a harness subagent declared in code) or a stored agent; an unknown id returns 404.
The stored definition is not the running conversation. It tells the runtime how the agent with that id answers. Session and thread routes then select the durable conversation path, and input routes run that agent on the same runtime in the agentId + sessionId + threadId scope.
Hosted Runtimes And Definitions
A hosted runtime is one AddHPDAgentRuntime(...) registration. It hosts one AgentRuntime, built from its runtime recipe, with the code agents, session store, agent store, and content store the recipe configures. That runtime knows its code agents and every definition in its agent store:
hosted runtime: support
├── agent: assistant (code, default)
├── agent definition: researcher (stored)
├── agent definition: writer (stored)
└── agent definition: reviewer (stored)- the
AddHPDAgentRuntime(...)registration name selects the hosted runtime; it is not an agent id - the recipe's
AddAgent(id, config)calls register the code agents; one of them is the default agent - the recipe's
WithAgentStore(...)selects where stored definitions live; without it they are in memory - stored definitions are created through
POST /agents
A recipe can register no code agent at all. That runtime serves only stored agents, has no default agent, and refuses an input that names no agent with 400 AgentIdRequired:
builder.Services.AddHPDAgentRuntime("studio", runtime => runtime
.WithFileSessionStore("App_Data/studio/sessions")
.WithAgentStore("App_Data/studio/agents"));Code agents are read-only and are never written to the agent store. Use Hosted Runtimes And Agents when deciding whether a new requirement needs another agent definition or another isolated runtime, and The Runtime And Its Agents for code and stored agents.
Definition Routes
| Operation | Route | Body | Success |
|---|---|---|---|
| Create a stored agent | POST /agents | CreateAgentRequest | 201 AgentDefinitionDto |
| List agents | GET /agents | none | 200 List<AgentDefinitionDto> |
| Get an agent | GET /agents/{agentId} | none | 200 AgentDefinitionDto |
| Update a stored agent | PATCH /agents/{agentId} | UpdateAgentRequest | 200 AgentDefinitionDto |
| Delete a stored agent | DELETE /agents/{agentId} | none | 204 |
Each route is the runtime.Agents read or write of the same name. MapHPDAgentAdministrationApi(...) and MapHPDAgent(...) map them. POST /agents requires an explicit agentId.
Code And Stored Agents
GET /agents lists both kinds of agent, code agents first, as full AgentDefinitionDto values:
| Field | Meaning |
|---|---|
id | The agent id inputs name |
source | Code or Stored |
config | The definition's portable part; the agent's name is config.name |
processLocal | One entry per process-local part a code agent carries (path, kind, description, details); empty for a stored agent |
isDefault | Whether the agent runs inputs that name no agent |
isEditable | false for a code agent, true for a stored agent |
createdAt, updatedAt | When a stored agent was created and last saved; null for a code agent |
owner | For a code agent, what declares it: runtime for an agent registered on the runtime builder, or the harness capability that declares a subagent |
metadata | A stored agent's metadata |
A code agent's config leaves out what cannot be serialized, such as a chat client instance, a native function, or a client middleware delegate. processLocal describes each of those parts without exposing secrets, for example:
{
"path": "clients.Chat.override",
"kind": "client",
"description": "Chat client TracingChatClient (provider 'openai', model 'gpt-5-mini')",
"details": {
"family": "Chat",
"type": "MyApp.TracingChatClient",
"ownership": "transferred",
"provider": "openai",
"model": "gpt-5-mini"
}
}Errors
A definition the runtime refuses returns 400 with validation errors keyed by code. Each message names the definition path it is about:
| Key | Meaning |
|---|---|
agent_provider_unknown | clients.{family}.provider.key names no provider of the runtime's composition |
agent_provider_family_unsupported | The provider does not implement that client family |
agent_harness_unknown | toolHarnesses[i].name is not the exact activation identity of a harness of the composition |
agent_harness_function_unknown | toolHarnesses[i].functions[j] names a function the harness does not declare |
agent_middleware_unknown | middlewares[i].name names no middleware of the composition |
agent_definition_process_local | The definition carries a process-local part; this occurs in-process only, because process-local members do not deserialize from JSON |
config | Errors without a code of their own, such as shape errors and validation limits |
{
"status": 400,
"errors": {
"agent_harness_unknown": [
"agent_harness_unknown: 'toolHarnesses[0].name' names harness 'WebSearchTools', which is not the exact activation identity of a harness of the runtime's composition. Did you mean 'HPD-Agent.Harness.WebSearch:HPD.Agent.Harness.WebSearch:WebSearchTools'?"
]
}
}Read the identities a definition can name from GET /composition/harnesses, /composition/providers, and /composition/middleware.
Conflicts return 409 problems whose code extension names the conflict:
code | When |
|---|---|
agent_definition_read_only | POST, PATCH, or DELETE names a code agent's id. Change code agents in code. |
agent_definition_exists | POST names an id the agent store already has |
agent_definition_changed | The stored agent changed between the read and the write of a PATCH; read it again and retry |
In Process
In-process, the same operations are on runtime.Agents:
var agents = host.Runtime.Agents;
await agents.CreateAsync("writer", new AgentConfig()
.WithOpenAI(model: "gpt-5-mini")
.WithInstructions("Write clear, short drafts."));
var all = await agents.ListAsync();
var writer = await agents.GetAsync("writer");
await agents.UpdateAsync("writer", updatedConfig, expected: writer);
await agents.DeleteAsync("writer");ListAsync and GetAsync return AgentDefinition values with the same members as the DTO. Validate(config) returns the errors that keep a definition from being stored, without reading storage. CreateAsync and UpdateAsync throw ValidationException for those errors (its Errors start with the codes above), AgentDefinitionProcessLocalException for a definition that carries a process-local part, and AgentDefinitionReadOnlyException for a code agent's id, which DeleteAsync throws too. CreateAsync throws AgentDefinitionExistsException for a taken id. Passing expected makes the update optimistic: it throws AgentStoreConcurrencyException when the stored agent changed after it was read. Changing a stored agent retires its built instance, so the next run builds the new definition.
AgentConfig is mutable, so copy a definition before changing it. Clone() returns an independent copy:
var writer = await agents.GetAsync("writer");
var updated = writer!.Config.Clone();
updated.SystemInstructions = "Write clear, short drafts with a summary first.";
await agents.UpdateAsync("writer", updated, expected: writer);
// A new agent based on an existing one.
await agents.CreateAsync("editor", writer.Config.Clone());A code agent's Config is already its portable part, so it can be duplicated as a stored agent the same way. The copy is a stored agent: it is editable, and it has none of the code agent's process-local parts, which the code agent's ProcessLocal list names:
var assistant = await agents.GetAsync("assistant");
await agents.CreateAsync("assistant-copy", assistant!.Config.Clone());Core validation enforces structural validity, such as positive turn counts, nonnegative delays, valid URIs, and unique names. It does not impose fixed upper limits on operating budgets such as turns, retries, or circuit-breaker thresholds. An application that protects shared compute, billing, or availability sets runtime limits with WithDefinitionValidationLimits(...) in the recipe. The runtime then applies them to every definition it registers or writes: code agents at startup and stored agents created or updated over HTTP or through runtime.Agents. Omit the limits when the agent definition should own those choices.
builder.Services.AddHPDAgentRuntime("assistant", runtime => runtime
.AddAgent("assistant", definition)
.WithDefinitionValidationLimits(new AgentConfigValidationLimits
{
MaximumAgenticIterations = 50,
MaximumRetries = 10
}));A definition that breaks a limit is refused with 400 under the config key over HTTP, and with ValidationException in-process.
Create And Update Bodies
Create accepts:
{
"agentId": "support-assistant",
"config": {
"clients": {
"chat": {
"provider": {
"key": "openai"
},
"modelName": "gpt-5-mini"
}
}
},
"metadata": {
"team": "support"
}
}Update accepts a patch. Omitted sections stay unchanged; metadata replaces the metadata, and clearMetadata: true clears it:
{
"config": {
"clients": {
"chat": {
"provider": {
"key": "openai"
},
"modelName": "gpt-5-mini"
}
}
}
}Keep provider setup aligned with the provider docs. Chat model configuration lives under clients.chat, and the provider key must be one of GET /composition/providers (a key or an alias).
Shared Runtime Customization
The runtime recipe passed to AddHPDAgentRuntime(...) is not part of a stored definition. Hosting applies it once to build the runtime:
builder.Services.AddHPDAgentRuntime("assistant", runtime => runtime
.AddAgent("assistant", definition)
.WithFileSessionStore("App_Data/assistant/sessions")
.WithAgentStore("App_Data/assistant/agents"));Nothing in the recipe is written back into /agents. Shared middleware, stores, secrets, and provider authentication registered in the recipe belong to the runtime and reach every agent it runs. Each stored definition selects its own chat model under clients.chat.
Updates And Running Threads
An updated stored definition takes effect on that agent's next run. A deleted definition is not recreated by runtime resolution; later inputs naming it return 404.
This is important for hosted UIs: a successful update does not mutate an already active thread execution in place, but it does affect the next run of that agent.