declare_agent()¶
Pre-register an AI agent with the Coalex platform. Call this at startup so the dashboard recognizes the agent before the first traces arrive. This sets up the merge key and lifecycle state for the agent.
Signature¶
Parameters¶
| Parameter | Type | Default | Description |
|---|---|---|---|
agent_id |
str |
required | Unique identifier for the agent. Must match the agent_id used in coalex_context(). |
display_name |
str \| None |
None |
Human-readable name shown in the dashboard. |
metadata |
dict \| None |
None |
Arbitrary key-value metadata to attach to the agent (e.g., team, owner, environment). |
All parameters are keyword-only (enforced by *).
Requires register() first
declare_agent() uses the endpoint and API key configured by register(). Calling it before register() raises RuntimeError.
Returns¶
AgentDeclaration¶
| Field | Type | Description |
|---|---|---|
agent_id |
str |
The agent identifier (mirrors the input parameter). |
lifecycle |
str |
The agent's lifecycle state. One of "active", "staging", or "deprecated". |
created |
bool |
True if the agent was newly registered, False if it already existed. |
Examples¶
Basic registration¶
import { register, declareAgent } from "@coalex-ai/sdk";
register({ endpoint: "https://your-org.coalex.ai", apiKey: "your-key" });
const agent = await declareAgent({
agentId: "claims-processor",
displayName: "Claims Processor",
});
console.log(agent.lifecycle); // "active"
console.log(agent.created); // true or false
With metadata¶
Notes¶
declare_agent()is idempotent -- calling it multiple times with the sameagent_idis safe. The agent is created on the first call and returned as-is on subsequent calls.- The API endpoint used is
POST /api/v1/agents. - Declaring agents before traces arrive ensures the dashboard shows the correct agent name and metadata from the start, rather than showing a raw
agent_id. - Network errors from the Coalex API raise
httpx.HTTPStatusError(Python) orError(TypeScript).
API Reference¶
coalex.agents.declare_agent ¶
declare_agent(
*,
agent_id: str,
display_name: str | None = None,
metadata: dict | None = None,
_config: CoalexConfig | None = None,
_api_key: str | None = None,
) -> AgentDeclaration
Register or declare an agent before traces arrive.
This is the building block for lazy agent registration. When COA-264's set_prompt() is implemented, it will call this internally to ensure the agent exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
Unique agent identifier (the merge key). |
required |
display_name
|
str | None
|
Optional human-friendly name. |
None
|
metadata
|
dict | None
|
Optional metadata (accepted but not persisted yet). |
None
|
_config
|
CoalexConfig | None
|
Override config (testing only). |
None
|
_api_key
|
str | None
|
Override API key (testing only). |
None
|