Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build and deploy AI applications on Azure AI Foundry using Microsoft's model catalog and AI services
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
foundry-agent/invoke/references/invocations-protocol.md
1# Invocations Protocol Guide23The `invocations` protocol is **bytes in, bytes out**. The platform is pure pass-through — the raw HTTP request body is forwarded to the container and the raw response is returned. The agent developer defines what the container accepts and returns. Unlike `responses` (OpenAI-compatible with platform-managed history), `invocations` gives full control to the container code.45## Input/Output Contract67| Aspect | `responses` | `invocations` |8|--------|------------|---------------|9| **Input** | `inputText` is a natural language message (e.g., `"What is the weather?"`) | `inputText` is forwarded as the **raw HTTP request body** — bytes in. Format as whatever the container's invoke handler expects (typically JSON) |10| **Output** | Structured OpenAI response with `output_text` | **Raw response bytes** from the container — JSON, text, or SSE events. Format is defined by the agent developer |11| **Conversation history** | Platform-managed via `conversationId` | Agent-managed via session filesystem; `conversationId` does **not** apply |12| **Streaming** | Platform-managed via `stream: true` | Agent-controlled; `stream` parameter does **not** apply |1314## Discovering the Expected Input Schema1516> ⚠️ **Do not guess the invocations request body.** The developer defines the schema in the container's invoke handler. The platform does not validate or transform the payload.1718### 1. Fetch the OpenAPI Spec (Preferred)1920Agents can register an OpenAPI spec that describes the expected request/response format. Fetch it from:2122```text23GET {projectEndpoint}/agents/{agentName}/endpoint/protocols/invocations/docs/openapi.json24```2526If the developer registered an `openapi_spec` when creating the server, this returns the full API contract. If not registered, it returns 404.2728### 2. Inspect Agent Source Code2930Look at the agent's invoke handler — the function registered with `@app.invoke_handler` (Python) or equivalent. The handler reads the raw request (e.g., `request.json()` for JSON, `request.body()` for raw bytes) and returns a `Response`.3132### 3. Ask the User3334If neither the OpenAPI spec nor source code is available, ask the user for the expected request body format before invoking.3536## Examples3738**Responses protocol** (default):3940```text41agent_invoke(projectEndpoint, agentName, inputText: "What is the weather in Seattle?")42→ Structured response with output_text43```4445**Invocations protocol** — agent expects `{"message": "<text>"}`:4647```text48agent_invoke(projectEndpoint, agentName, inputText: "{\"message\":\"hello\"}", protocol: "invocations", sessionId: "<session-id>")49→ Raw bytes from container, e.g.: {"response": "Hi there!", "session_id": "abc123"}50```5152## Common Use Cases5354| Scenario | Why Invocations |55|----------|----------------|56| Webhook receiver (GitHub, Stripe, Jira) | External system sends its own payload format |57| Non-conversational processing (classification, extraction) | Input is structured data, not a chat message |58| Custom streaming protocol (AG-UI) | Needs raw SSE control, not OpenAI-compatible streaming |59| Protocol bridge (proprietary systems) | Caller has its own protocol that doesn't map to `/responses` |6061## Error Handling6263| Error | Cause | Resolution |64|-------|-------|------------|65| 400/422 or invocation failed | Request body does not match what the container expects | Fetch OpenAPI spec or inspect handler code for the correct schema |66| 404 on OpenAPI spec | Developer did not register an `openapi_spec` | Inspect handler source code or ask the user for the API contract |67| Empty response | Agent returned no content | Check agent logs via `session_logstream`; verify the handler processes the request body correctly |68