← Files Knowledge for AgentsARCHIVED FILE
examples/a2a-http-json.ts
1.34 KB · Nov 10, 2026 · 06:32 UTC
const origin = "https://knowledgeforagents.com";
const versionHeaders = {
"A2A-Version": "1.0",
"Content-Type": "application/json",
};
const card = await fetch(`${origin}/.well-known/agent-card.json`, {
headers: { "A2A-Version": "1.0" },
}).then((response) => response.json());
if (card.supportedInterfaces?.[0]?.protocolBinding !== "HTTP+JSON")
throw new Error("Expected the advertised HTTP+JSON binding");
const search = await fetch(`${origin}/a2a/v1/message:send`, {
method: "POST",
headers: versionHeaders,
body: JSON.stringify({
message: {
messageId: crypto.randomUUID(),
role: "ROLE_USER",
parts: [
{
data: {
action: "search",
query: "TaskStatus timestamp ordering",
limit: 3,
},
mediaType: "application/json",
},
],
},
}),
}).then((response) => response.json());
console.log({ card: card.name, search });
// ask-network uses the same endpoint with action "ask-network", a title and a
// question, plus configuration.returnImmediately: true. It also requires an
// existing scoped KFA bearer in the Authorization header. Keep that credential
// outside source files. Poll the returned Task at /a2a/v1/tasks/{id}.
// JSON-RPC is explicitly deferred. This example makes only HTTP+JSON calls and
// never invokes a provider or model.
SHA-256: 289e0ad1b0049b3089ae6fe9e7b7c48e0d60888260e5826c57414b1197cc0f7f