/** * Agent Conversations API — types. * * Mirrors `/agents/conversations` and `/agents/runs` on the Narrative Data * Collaboration Platform (RFC 7807 errors; OpenAI-Assistants-shaped semantics). * * Two tool dimensions: * - `mcp_servers[]` — server-side, resolved by the platform via MCP. Model sees * each tool as `{alias}-{name}`. * - `tools[]` — caller-declared. Dash-free names. When called, the run pauses * at `requires_action`; resume by posting a follow-up run with * `payload.kind: "tool_outputs"`. */ export type ConversationId = string; export type RunId = string; export type ClientOpId = string; export type ConversationVersion = number; export type ToolUseId = string; export type AgentModel = "anthropic.claude-haiku-4.5" | "anthropic.claude-sonnet-4.5" | "anthropic.claude-sonnet-4.6" | "anthropic.claude-sonnet-5.0" | "anthropic.claude-sonnet-5.5" | "anthropic.claude-opus-4.5" | "anthropic.claude-opus-4.6" | "anthropic.claude-opus-4.7" | "anthropic.claude-opus-4.8" | "anthropic.claude-opus-5.0" | "anthropic.claude-opus-5.5" | "openai.gpt-oss-120b" | "openai.gpt-4.1" | "openai.o4-mini" | (string & {}); export type ExecutionCluster = "shared" | "dedicated"; /** Subset of JSON Schema Draft 2020-12 accepted by Bedrock structured output. */ export type JsonSchemaObject = Record; export interface McpServerConfig { /** 1–8 char `[a-zA-Z][a-zA-Z0-9]{0,7}` — namespace prefix for the server's tools. */ alias: string; url: string; description?: string; /** * Reference to a registered external-MCP OAuth connection (from `POST /mcp-connections`, * see {@link McpConnectionsApi}). Set for an external server that requires user * authorization — the platform resolves and refreshes the connection's bearer token * server-side; it never appears in the payload. Omit for public or Narrative-owned MCPs. */ connection_id?: string; } export interface ToolSpec { /** Caller-declared tools must NOT contain a dash. MCP tools' bare name. */ name: string; description: string; input_schema: JsonSchemaObject; /** Defaults to true. Leave true in production. */ strict?: boolean; } /** How hard a model should think, for models that take an effort scale. */ export type ThinkingEffortLevel = "low" | "medium" | "high"; /** * What a model should do about thinking. Models differ in which form they take: * one accepts an effort level, another a token budget, some both. A setting is * only valid against the model it is sent to, and one the model cannot honour is * a 400 rather than a silent downgrade. * * Omit the field entirely to get the model's own behaviour. * * Reasoning comes back as `reasoning` content blocks on the assistant turn, * ahead of the answer. Some models return their working as words; others return * only a signature. */ export type ThinkingSetting = "disabled" | { type: "effort"; level: ThinkingEffortLevel; } | { type: "budget"; budget_tokens: number; }; export interface ConversationDefaults { model: AgentModel; data_plane_id: string; execution_cluster: ExecutionCluster; compute_pool_id?: string; max_iterations?: number; max_tokens?: number; temperature?: number; /** * Whether the model should reason before answering, and how hard. * * A token budget must be at least 1024 and smaller than `max_tokens`: * thinking is spent from the same output budget as the answer, so a budget * that fills it leaves nothing to answer with. * * Cannot be combined with `tool_choice: { kind: "specific_tool" }` on a run. * A forced tool stops the model reasoning, so that combination is refused * rather than half-honoured. */ thinking?: ThinkingSetting; output_format_schema?: JsonSchemaObject; mcp_servers?: McpServerConfig[]; tools?: ToolSpec[]; } export interface CreateConversationRequest { name?: string; system_prompt?: string; defaults: ConversationDefaults; } export interface ConversationResponse { id: ConversationId; company_id: number; user_id: number; name: string | null; system_prompt: string | null; defaults: ConversationDefaults; version: ConversationVersion; created_at: string; updated_at: string; } export type RunStatus = "pending" | "running" | "completed" | "requires_action" | "failed"; export interface UserMessagePayload { kind: "user_message"; text: string; } export interface ToolOutput { tool_use_id: ToolUseId; /** Plain text. Serialize JSON results before sending. */ content: string; is_error?: boolean; } export interface ToolOutputsPayload { kind: "tool_outputs"; outputs: ToolOutput[]; } export type RunPayload = UserMessagePayload | ToolOutputsPayload; export type ToolChoice = { kind: "auto"; } | { kind: "any"; } | { kind: "specific_tool"; name: string; /** Set when pinning an MCP-resolved tool; omit for caller-declared. */ mcp_alias?: string | null; }; /** Sparse override applied per-run; lists replace wholesale. */ export interface RunConfigOverride { model?: AgentModel; data_plane_id?: string; execution_cluster?: ExecutionCluster; compute_pool_id?: string; max_iterations?: number; max_tokens?: number; temperature?: number; /** Shadows the conversation's setting for this run only. See {@link ConversationDefaults.thinking}. */ thinking?: ThinkingSetting; output_format_schema?: JsonSchemaObject; mcp_servers?: McpServerConfig[]; tools?: ToolSpec[]; } export interface CreateRunRequest { client_op_id: ClientOpId; expected_version: ConversationVersion; payload: RunPayload; tool_choice?: ToolChoice; config_override?: RunConfigOverride; } export interface PendingToolCall { tool_use_id: ToolUseId; /** Wire-form name. For caller-declared tools, dash-free. */ name: string; arguments: Record; } export interface AgentInferenceUsage { prompt_tokens: number; completion_tokens: number; total_tokens: number; } export interface RunError { /** Stable incident code, e.g. "AgentLoopMaxIterationsExceeded". */ type: string; message: string; title?: string; docs_url?: string; } /** * A turn the agent loop has produced during an active run but has not yet * committed to the conversation's message log. The loop appends one of these * per produced turn (assistant `tool_use`, tool `tool_result`, ...) to * `agent_run_live_messages`, ordered by `turn_index`. Surfaced on * `RunResponse.live.messages` only while the run is non-terminal; finalize * clears them and re-writes the same content as committed messages with * gap-free `sequence_no`. * * Order by `turn_index` (run-local), not `sequence_no` — live turns do not * carry `sequence_no` and never collide with the committed table. */ export interface LiveRunTurn { turn_index: number; role: AgentMessageRole; content_blocks: ContentBlock[]; /** * Same meaning as on a committed message, but empty while the turn is still * streaming: the answer is resolved when the run finalizes. */ final_answer_from?: BlockId[]; } /** * The conversation's current, still-mutating state. Always present on a run * response (independent of `status`). `messages` streams the run's produced * turns while non-terminal and is empty once the run reaches a terminal * state — at that point the same content is available on * `GET /agents/conversations/{id}/messages?since={version}` as committed * turns with `sequence_no`. */ export interface RunLiveProgress { /** * The conversation's current display name, or `null`/absent if it has * none yet. The platform auto-generates one from the first user message * shortly after the first run is created. */ current_name?: string | null; messages: LiveRunTurn[]; } export interface RunResponse { id: RunId; conversation_id: ConversationId; company_id: number; user_id: number; client_op_id: ClientOpId; status: RunStatus; tool_choice?: ToolChoice; effective_config: ConversationDefaults; iterations_used?: number | null; usage?: AgentInferenceUsage | null; submitted_inference_job_ids: string[]; pending_tool_calls: PendingToolCall[]; final_text?: string | null; /** * The model's final answer as a JSON value conforming to the caller's * `output_format_schema`. Populated on `status: completed` when the * caller supplied an `output_format_schema` (structured mode). Mutually * exclusive with `final_text`. */ final_structured_output?: unknown; error?: RunError | null; started_at: string; completed_at?: string | null; /** * The conversation's current, still-mutating state (e.g. its * auto-generated name) plus in-flight tool-loop progress while the run * is non-terminal. Always present on a run response; `messages` is * empty after finalize, at which point consumers should fall back to * `listAgentConversationMessages({ since: version-at-run-start })` for * the committed turns. */ live: RunLiveProgress; } export type AgentMessageRole = "user" | "assistant" | "tool"; /** * Identifier a block was produced under, e.g. `b_c08cf800_02` — the first eight * characters of the inference job's id and the block's position in that * response. Present on blocks the platform produced; absent on blocks a caller * sent, and on turns stored before ids existed. */ export type BlockId = string; export interface TextContentBlock { type: "text"; text: string; id?: BlockId; } export interface ToolUseContentBlock { type: "tool_use"; tool_use_id: ToolUseId; /** Fully-aliased wire name (`{alias}-{tool_name}` for MCP, bare for caller-declared). */ name: string; arguments: Record; id?: BlockId; } export interface ToolResultContentBlock { type: "tool_result"; tool_use_id: ToolUseId; content: ContentBlock[]; is_error: boolean; id?: BlockId; } /** * The model's own working, on an assistant turn where the run asked for * thinking. Comes first in the turn, ahead of the answer. * * `text` is optional and often absent: some models return their reasoning as * words, others return only a `signature` and keep the words to themselves. A * block with no `text` still means the model reasoned — and that those tokens * were billed — so don't read its absence as "nothing happened". * * `signature` is issued by the provider and opaque: not a hash you can verify * or a token you can decode. Send the block back unchanged to continue a turn * as the model left it, or drop it — a continuation without reasoning blocks is * accepted. */ export interface ReasoningContentBlock { type: "reasoning"; text?: string; signature: string; id?: BlockId; } /** Reasoning the provider encrypted rather than returning. Nothing to display; kept so a turn can be replayed whole. */ export interface RedactedReasoningContentBlock { type: "redacted_reasoning"; /** Base64 of the encrypted reasoning. */ data: string; id?: BlockId; } export type ContentBlock = TextContentBlock | ToolUseContentBlock | ToolResultContentBlock | ReasoningContentBlock | RedactedReasoningContentBlock; export interface MessageDto { id: string; sequence_no: number; role: AgentMessageRole; content_blocks: ContentBlock[]; run_id: RunId; created_at: string; /** * Ids of the blocks this turn's answer was taken from — always text blocks * that are present in `content_blocks`, and empty on a turn that answered * nothing (a tool-call turn, a user's message, a turn still streaming). * * Render the reply from these rather than from every text block: with * thinking on, a model may narrate its working as ordinary text before * answering, and that narration is persisted deliberately. Use * {@link answerTextBlocks}, which also handles turns stored before ids * existed. */ final_answer_from?: BlockId[]; } export interface ListMessagesResponse { current_version: ConversationVersion; messages: MessageDto[]; } export interface AgentRfcError { type?: string | null; title: string; status: number; detail?: string; instance?: string; log_id: string; debug?: Record | null; } export declare const TERMINAL_RUN_STATUSES: ReadonlyArray; export declare function isTerminalRunStatus(status: RunStatus): boolean; /** Narrows to a reasoning block, whose `text` may still be absent. */ export declare function isReasoningBlock(block: ContentBlock): block is ReasoningContentBlock; /** * The text blocks of a turn that make up its reply — what to render as the * assistant's message. * * Two shapes of turn exist and both are live, so which blocks count depends on * whether the platform produced this turn: * * - **A turn with block ids** is one we produced. Its reply is exactly the * blocks named by `final_answer_from`, which is empty while the turn is * still streaming and on turns that answer nothing (a tool-call turn). Empty * means *render nothing yet* — not "fall back to everything" — because such * a turn may also hold the model's working as ordinary text, and that * narration is not the reply. * - **A turn without block ids** is a caller's message or a turn stored before * ids existed. There is no pointer to consult, so its reply is every text * block, which is how these turns have always rendered. * * Ids the pointer names but the turn doesn't contain are ignored rather than * trusted, so a malformed pointer renders nothing instead of throwing. */ export declare function answerTextBlocks(turn: { content_blocks: ContentBlock[]; final_answer_from?: BlockId[]; }): TextContentBlock[];