Skip to main content
Use azd ai agent invoke to send messages to your agent, either the deployed version in Microsoft Foundry or a locally running instance. You learn how to choose an agent, use direct endpoints, manage sessions, send files, pin versions, and inspect raw responses.

Prerequisites

Invoke the deployed agent

  • Send a prompt to the deployed agent:

Invoke a specific agent

  • If your project contains multiple agents, specify which one to invoke:

Invoke a specific deployed endpoint

When you want to invoke a specific deployed agent without depending on the active azd environment or azure.yaml, use --agent-endpoint to point directly at the deployed agent’s URL. This pattern is useful from a script outside the project, from a coding agent, or when you test a specific agent version.
  • Pass the deployed agent endpoint:
    --agent-endpoint overrides azd environment and azure.yaml resolution, so you don’t need to be inside an azd project directory to use it.

Invoke locally

  • Invoke a local agent:
    The agent must already be running with azd ai agent run in another terminal.

Invoke on a custom local port

  • If your agent is running on a non-default port, pass --port:

Choose a protocol

The protocol used for invoke is determined by the protocols field of the azure.ai.agent service in azure.yaml.
  • responses — sends a standard OpenAI Responses API request with {"input": "your message"}. Conversation history is managed automatically.
  • invocations — sends whatever payload your agent code expects. Use --input-file (-f) with a JSON file matching the schema your handler defines.
For invocations agents, check the sample’s README or inspect the handler entry point to understand the expected payload.
  • If your agent implements multiple protocols, pass --protocol (-p) to choose:

Manage sessions

Sessions are persisted per-agent. When you invoke an agent, azd saves the session ID locally so the next invoke automatically continues the same session and maintains conversation history across calls.

Start a new session

  • Discard the saved session and begin fresh:

Use a specific session ID

  • Pass an existing session ID:

Send a file as input

For structured or large payloads, especially with the invocations protocol, pass a JSON file.
  1. Send a file:
  2. Or send a file to a specific agent:

Invoke a deployed version

When an agent has multiple deployed versions, pin a specific one with --version. azd creates or reuses a session backed by that version, so each version keeps its own conversation state.
  • Pin a version:
    --version can’t be combined with --local or --session-id because sessions are bound to a version when they’re created.

Set a custom timeout

  • Pass a timeout in seconds:
    The default timeout is 1800 seconds (30 minutes). Use --timeout 0 for no timeout.

Pass isolation keys

Agents configured with Foundry header-based isolation require per-user or per-chat keys on every request. Pass them with --user-isolation-key and --chat-isolation-key.
  • Pass isolation keys with the request:
For the full pattern, including how sessions, files, and monitor commands use the same flags, see Pass isolation keys to a hosted agent.

Inspect the raw HTTP response

When you need to see exactly what the server returned, including response headers like the agent version, status line, and the unmodified body, pass --output raw (-o raw).
  • Request raw output:
    In raw mode, friendly summary lines like Session: and Invocation: are suppressed and the HTTP response is dumped verbatim. This mode is useful for debugging server behavior and confirming which agent version handled the call.