fix: normalize missing agent handoff edges

This commit is contained in:
Danny Avila 2026-07-26 16:35:56 -04:00
parent 21002b2563
commit c45c70f469
4 changed files with 36 additions and 3 deletions

View file

@ -465,6 +465,24 @@ describe('summarizationConfig field passthrough', () => {
// Suite 5: Multi-agent + per-agent overrides
// ---------------------------------------------------------------------------
describe('multi-agent + per-agent overrides', () => {
it('normalizes missing persisted edges before creating the SDK graph', async () => {
await createRun({
agents: [makeAgent({ id: 'agent_1' }), makeAgent({ id: 'agent_2' })] as never,
signal: new AbortController().signal,
streaming: true,
streamUsage: true,
});
const createMock = Run.create as jest.Mock;
const runConfig = createMock.mock.calls[0][0] as {
graphConfig: { type: string; edges: unknown[] };
};
expect(runConfig.graphConfig).toMatchObject({
type: 'multi-agent',
edges: [],
});
});
it('different agents get different effectiveMaxContextTokens', async () => {
const agents = await callAndCapture({
agents: [

View file

@ -73,6 +73,20 @@ const createSdkProcess = (): jest.MockedFunction<ProcessHandoffReception> =>
});
describe('applyCustomHandoffPromptKeyCompatibility', () => {
it('leaves multi-agent graphs without edges unpatched', () => {
const sdkProcess = createSdkProcess();
const { run, graph } = createRun(sdkProcess);
const originalProcess = graph.processHandoffReception;
// Persisted agents can predate `edges`, even though the current SDK type requires it.
const graphConfig = {
type: 'multi-agent',
agents: [],
} as unknown as RunConfig['graphConfig'];
expect(() => applyCustomHandoffPromptKeyCompatibility(run, graphConfig)).not.toThrow();
expect(graph.processHandoffReception).toBe(originalProcess);
});
it('recovers a custom prompt key for scalar and array handoff endpoints', () => {
const sdkProcess = createSdkProcess();
const { run, graph } = createRun(sdkProcess);

View file

@ -121,7 +121,8 @@ export function applyCustomHandoffPromptKeyCompatibility(
return;
}
const hasCustomPromptKey = graphConfig.edges.some((edge) => {
const edges = graphConfig.edges ?? [];
const hasCustomPromptKey = edges.some((edge) => {
const promptKey = edge.promptKey;
return (
edge.edgeType !== 'direct' &&
@ -152,7 +153,7 @@ export function applyCustomHandoffPromptKeyCompatibility(
return result;
}
const labels = getCustomPromptLabels(graphConfig.edges, agentId);
const labels = getCustomPromptLabels(edges, agentId);
if (labels.length === 0) {
return result;
}

View file

@ -1362,7 +1362,7 @@ export async function createRun({
const graphConfig: RunConfig['graphConfig'] = {
signal,
agents: agentInputs,
edges: agents[0].edges,
edges: agents[0].edges ?? [],
};
if (agentInputs.length > 1 || ((graphConfig as MultiAgentGraphConfig).edges?.length ?? 0) > 0) {