Hi,
I have been building a workflow using the new Microsoft Foundry, and once I've tested it in the Portal UI, using the Preview feature, I have published my workflow, giving me a endpoint following:
https://<resource-name>.services.ai.azure.com/api/projects/<project-name>/applications/<workflow-name>/protocols/activityprotocol?api-version=2025-11-15-preview
This is currently getting called via a fetch request in my localhost environment. To authenticate, I'm using this helper function:
const { DefaultAzureCredential } = require("@azure/identity");
const cred = new DefaultAzureCredential();
async function getAiAzureBearer() {
const t = await cred.getToken("https://ai.azure.com/.default");
if (!t?.token) throw new Error("Falha ao obter token (ai.azure.com)");
return t.token;
}
And the request is being sent via:
async function runFoundryWorkflow({ invokeUrl, input }) {
const token = await getAiAzureBearer();
const bodyObj = { input };
const bodyStr = JSON.stringify(bodyObj);
const res = await fetch(invokeUrl, {
method: "POST",
headers: {
Authorization: `Bearer ${token}`,
"Content-Type": "application/json",
"Accept": "application/json"
},
body: bodyStr,
});
const text = await res.text();
if (!res.ok) {
let reqId = null;
try { reqId = JSON.parse(text)?.error?.additionalInfo?.request_id; } catch (_) { }
console.error("[FOUNDRY WF ERROR]", {
status: res.status,
request_id: reqId,
payload_bytes: Buffer.byteLength(bodyStr, "utf8"),
payload_head: bodyStr.slice(0, 2000),
response_head: text.slice(0, 2000),
headers: Object.fromEntries(res.headers.entries()),
});
throw new Error(`Workflow HTTP ${res.status}: ${text}`);
}
try { return JSON.parse(text); } catch { return text; }
}
But I always receive the same response, HTTP 500 error:
"error": {
"code": "server_error",
"message": "An error occurred while processing your request. You can retry your request, or contact us if the error persists. Please include the request ID <requestId> in your message.",
"type": "error",
"details": [],
"additionalInfo": {
"request_id": "<requestId>"
}
}
I'm not sure whether my Workflow YAML is assigning the body of the request to the correct variable, it should assign the "input" in the body to the Local.input variable. But since I'm triggering it via the HTTP request (and not OnConversationStart), it probably isn't, and that is the only reason I can think that could be causing the 500 error. Here is the YAML of my workflow:
kind: workflow
trigger:
kind: OnConversationStart
id: trigger_wf
actions:
- kind: SetMultipleVariables
id: node-1771965874882
assignments:
- variable: Local.final_result
value: =
- variable: Local.input
value: =
- variable: Local.classified
value: =
- variable: Local.classification_obj
value: =
- variable: Local.final_result_obj
value: =
- kind: InvokeAzureAgent
id: node-1771965870373
agent:
name: doc-classifier
conversationId: =System.ConversationId
input:
messages: =Local.input
output:
autoSend: true
responseObject: Local.classification_obj
- kind: InvokeAzureAgent
id: node-1771965871830
agent:
name: doc-extractor
conversationId: =System.ConversationId
input:
messages: =Local.classification_obj
output:
autoSend: true
responseObject: Local.final_result_obj
- kind: EndConversation
id: node-1771966048400
id: ""
name: document-classifier-and-extractor
description: ""
I have tried changing the signature to CognitiveServices, but returns that it was impossible to validate JWT token (and doesn't really make any sense).
I have also tried different kinds of payload, like wrapping it in { } and with different names. Also tried setting the value of Local.input to System.LastMessage.Text and System.LastMessageText (don't know the difference), but to no avail.
I've been trying this for 3 days now and just can't find the right documentation on how to call the endpoint of the published (new) Microsoft Foundry Workflow.
Thanks in advance.