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
- An initialized hosted agent project. To create one, see Initialize an agent project.
- The azd Foundry extensions installed. For installation steps, see Install the azd Foundry extensions.
- An authenticated Azure Developer CLI session. Run
azd auth loginif needed. - For remote invocation, a deployed hosted agent. To deploy one, see Deploy a hosted agent.
- For local invocation, a running local agent. To start one, see Run a hosted agent locally with the Azure Developer CLI.
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 orazure.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-endpointoverrides azd environment andazure.yamlresolution, 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 runin 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 theprotocols 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.
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 theinvocations protocol, pass a JSON file.
-
Send a file:
-
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:
--versioncan’t be combined with--localor--session-idbecause 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 0for 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:
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:andInvocation: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.
Related content
- Isolate hosted agent sessions per user for per-user isolation in multi-tenant agents.
- Run a hosted agent locally with the Azure Developer CLI to start your agent for local development.
- Monitor hosted agent logs with the Azure Developer CLI to inspect deployed agent behavior.