Overview
The most powerful way to use the Context SDK is to let your LLM do the driving. Context provides one marketplace with two modes (Query + Execute), and there are two primary approaches:If you want the public contract for Context’s managed Query runtime (inputs, response shapes, debugging surfaces), see Query and Chat Runtime. This page focuses on the developer-facing pattern for building your own agent loop.
Choose The Contract First
The first-party chat app is just a client of the same Query contract external SDK users get. If you want the server-managed answer package, use Query. If you want direct primitives for your own loop, use Execute.
Option 1: Query API (Recommended)
The simplest path is to let Context’s server handle everything:answer_with_evidencefor human-facing premium answers (default, chat parity)evidence_onlyfor agent-facing evidence packages without prose synthesis
marketIntelligence, view.rows, view.columns, and the public controller fields stopReason, issueClass, actionsTaken, and controller.
See the TypeScript SDK Reference or Python SDK Reference for the full API.
Option 2: Build Your Own Loop
If you want full control over tool selection, argument construction, and result synthesis, follow the Discovery → Schema → Execution loop below (typically in Execute mode with spending limits).This pattern enables your agent to find and use tools it has never seen before, with true autonomous capability discovery at runtime.
The Loop
1
Discover
Let your Agent search for tools based on the user’s intent
2
Inspect Schemas
Feed discovered tool schemas to your LLM so it understands how to use them
3
Execute
When the LLM generates arguments, pass them directly to the SDK
Phase 1: Discover
Let your Agent search for tools based on the user’s intent. The marketplace returns relevant tools ranked by match quality.- The SDK searches the Context marketplace
- Returns tools matching the semantic intent of the query
- Each tool includes its name, description, price, and available methods
Phase 2: Inspect Schemas
Feed the discovered tool schemas (inputSchema) directly to your LLM’s system prompt. This allows the LLM to understand exactly how to format the arguments, just like reading a manual.
- The LLM sees the exact JSON Schema for each tool’s inputs and outputs
- It can self-construct valid arguments without any hardcoding
- Output schemas let the LLM know what data it will receive back
Phase 3: Execute
When the LLM generates the arguments, pass them directly to the SDK.Handling Data (Outputs)
Context Tools return raw, structured JSON data (viastructuredContent). This allows your Agent to programmatically filter, sort, or analyze results before showing them to the user.
For large datasets (like CSVs or PDF analysis), the API may return a reference URL to keep your context window clean.
Full Agentic Loop Example
Here’s a complete implementation of an autonomous agent using the Discovery → Schema → Execution pattern:Why This Pattern Matters
No Hardcoding
Your agent isn’t limited to tools you knew about at build time.
Network Effect
As new builders add tools to the marketplace, your agent automatically becomes more capable without any code changes.
Self-Constructing
LLMs can read schemas and construct valid arguments autonomously.
Future-Proof
New tools in the marketplace are instantly available to your agent.

