Agent Invocation
The client.agents resource provides invoke and stream methods with full generic type inference.
Basic Invocation
import { FaosClient } from '@faos/sdk';
const client = new FaosClient({ apiKey: 'faos_sk_...' });
const response = await client.agents.invoke(
'credit-risk-analyst',
{ query: 'Analyze Q1 2024 revenue trends' },
);
console.log(response.result); // Record<string, unknown>
console.log(response.metadata); // { model, durationMs, ... }
console.log(response.usage); // { promptTokens, completionTokens, totalTokens }
console.log(response.requestId); // For debugging
Generic Type Inference
The key DX feature: pass a generic parameter for fully typed results.
interface CreditAnalysis {
insights: string[];
riskScore: number;
recommendation: string;
}
const res = await client.agents.invoke<CreditAnalysis>(
'credit-risk-analyst',
{ query: 'Analyze Q1 2024' },
);
// All fully typed:
res.result.insights; // string[]
res.result.riskScore; // number
res.result.recommendation; // string
Without a generic, result defaults to Record<string, unknown>.
Multi-Tenant Invocation
const response = await client.agents.invoke(
'credit-risk-analyst',
{ query: 'Analyze Q1' },
{ tenantId: 'tenant-abc123' },
);
A2A Format
Auto-detected when task key is present in input:
// FAOS-native format
await client.agents.invoke('analyst', { query: '...' });
// A2A format — auto-detected
await client.agents.invoke('analyst', {
task: { id: 'task-1', input: { query: '...' } },
});
Response Type
interface FaosResponse<T = Record<string, unknown>> {
result: T;
metadata: ResponseMetadata;
usage: TokenUsage;
requestId: string;
}
interface TokenUsage {
promptTokens: number;
completionTokens: number;
totalTokens: number;
}