What is a context
A context (identified by a server-generatedcontextId) is a logical grouping of related messages, tasks, and artifacts, providing context across a multi-turn conversation. It enables you to associate multiple tasks with a single patient encounter, call, or workflow, ensuring continuity and proper scoping of shared knowledge.
The contextId is always created on the server. You never generate it client-side. This ensures proper state management and prevents conflicts.
In v2, contexts are first-class resources with their own API endpoints. You can inspect and delete contexts independently of agents. Contexts are created implicitly when you send a message; there is no create or update endpoint.
Context API endpoints
Listing contexts
GET /v2/agentic/contexts returns a paginated list of contexts. You can filter by:
agentId: Restrict to contexts owned by a specific agentfrom: Inclusive lower bound oncreatedAt(RFC 3339)to: Exclusive upper bound oncreatedAt(RFC 3339)
Getting a context
GET /v2/agentic/contexts/{contextId} returns the context’s metadata together with its tasks, oldest first. Each task carries its full message history; the user’s prompt for a task is the ROLE_USER message within that task’s history. Use the historyLength query parameter to cap the number of history messages returned per task.
Deleting a context
DELETE /v2/agentic/contexts/{contextId} deletes the context and its associated data. This is irreversible.
See Work with contexts for a detailed guide.
Data isolation and scoping
Contexts provide strict data isolation. Data can never leak across contexts. EachcontextId creates a completely isolated conversation scope. Messages, tasks, artifacts, and any data within one context are completely inaccessible to agents working in a different context. This ensures:
- Privacy and security: Patient data from one encounter cannot accidentally be exposed to another encounter
- Data integrity: Information from different workflows remains properly separated
- Compliance: You can confidently scope sensitive data to specific contexts without risk of cross-contamination
Using context for automatic memory management
The simplest way to use context is to let the framework automatically manage conversation memory:- First message: Send your message without a
contextId. The server creates a new context automatically. - Response: The server’s response includes the newly created
contextIdin the task or message object. - Subsequent messages: Include that
contextIdin your requests. Memory from previous messages in that context is automatically managed and available to the agent.
contextId in your request, the agent has access to all previous messages, artifacts, and state within that specific context only. Data from other contexts is completely isolated and inaccessible.
Standalone requests
If you don’t want automatic memory management, always send messages without acontextId. Each message is treated as a standalone request without access to prior conversation history. This is useful for one-off queries, testing, and scenarios where you want explicit control over what context is included.
Passing additional context with each request
In addition to automatic memory management viacontextId, you can pass additional context in each request by including data parts in your message. This is useful when you want to provide specific structured data, summaries, or other context that should be considered for that particular request.
Example: Passing additional context as a data part
Example: Passing additional context as a data part
- Provide structured data (patient records, clinical facts, etc.) alongside text
- Include summaries or distilled information from external sources
- Pass metadata or configuration that should be considered for this specific request
- Combine automatic memory (via
contextId) with explicit context (via data parts)
How memory works
The Agentic Framework uses an intelligent memory system that automatically indexes content within a context. Semantic retrieval requires a memory connector to be attached to the agent.Automatic indexing
Every text part and data part you send in messages is automatically indexed and stored in the context’s memory. This includes text content from user and agent messages, structured data from data part objects, artifacts generated by tasks, and any other content that flows through the context.Semantic retrieval
The memory system operates like a RAG (Retrieval Augmented Generation) pipeline. When a memory connector is attached to the agent and the agent decides to call thesearch_memory tool:
- Semantic search: The tool performs semantic search across all indexed content in the context’s memory
- Relevant retrieval: It retrieves the most semantically relevant information based on the current query or task
- Agent integration: The retrieved content is returned to the LLM as tool output, making it available for reasoning
search_memory tool; the framework does not automatically inject retrieved context into prompts.
Context vs. reference task IDs
The framework provides two mechanisms for linking related work:contextId: Groups multiple related messages, tasks, and artifacts together. This provides automatic memory management and is sufficient for most use cases.referenceTaskIds: An optional list of specific past task IDs within the same context that should be treated as explicit inputs or background. These are scoped to a context; they reference tasks within the samecontextId.
referenceTaskIds since the automatic memory provided by contextId is sufficient. Use referenceTaskIds only when you need to explicitly direct the agent to pay attention to specific tasks or artifacts within the context.
Context TTL and expiration
Contexts can have an expiration time (expiresAt). When a context expires, it is automatically cleaned up. A null expiresAt means the context does not expire.
Ephemeral agents (with
lifecycle: "ephemeral") may have shorter context TTLs. Persistent agents (with lifecycle: "persistent") typically have longer-lived contexts. Check the expiresAt field on context responses to understand the lifetime of a specific context.Trace export
You can export OpenInference-format traces for a context to inspect the agent’s reasoning, connector calls, and tool usage:llm.token_count.total, tool.name, and input.value. This is useful for debugging, performance analysis, and compliance auditing.
See Export traces for a detailed guide.
Context and interaction IDs
If you are using contexts alongside Corti’s internal interaction representation (for example, when integrating with other Corti products that useinteractionId), note that these two concepts are currently not linked:
contextId(from the Agentic Framework) andinteractionId(from Corti’s internal systems) are separate concepts that you need to map yourself in your application- There is no automatic association between a Corti
interactionIdand an Agentic FrameworkcontextId
interactionId and contextId(s) in your own application state. If you need to share data across multiple contexts within the same interaction, explicitly pass it via data part objects.
Next steps
- Learn how to work with contexts via the API
- Read about exporting traces for observability
- Understand core concepts for the full vocabulary