Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions core/src/tools/agent_tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,12 +147,12 @@ export class AgentTool extends BaseTool {
const hasOutputSchema =
this.agent instanceof LlmAgent && this.agent.outputSchema;

const mergetText = lastEvent.content.parts.map((part) => part.text)
const mergedText = lastEvent.content.parts.map((part) => part.text)
.filter((text) => text)
.join('\n');

// TODO - b/425992518: In case of output schema, the output should be
// validated. Consider similar logic to one we have in Python ADK.
return hasOutputSchema ? JSON.parse(mergetText) : mergetText;
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
}
}
4 changes: 2 additions & 2 deletions core/src/tools/tool_confirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export class ToolConfirmation {
/** The hint text for why the input is needed. */
hint: string;

/** Whether the tool excution is confirmed. */
/** Whether the tool execution is confirmed. */
confirmed: boolean;

/**
Expand All @@ -33,4 +33,4 @@ export class ToolConfirmation {
this.confirmed = confirmed;
this.payload = payload;
}
}
}
21 changes: 21 additions & 0 deletions core/test/tools/function_tool_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,4 +199,25 @@ describe('FunctionTool', () => {
});
expect(result).toEqual(3);
});

it('wraps errors from execute function', async () => {
const tool = new FunctionTool({
name: 'errorTool',
description: 'Throws an error.',
parameters: z.object({}),
execute: async () => {
throw new Error('Test error');
},
});
try {
await tool.runAsync({
args: {},
toolContext: emptyContext,
});
} catch (e) {
expect((e as Error).message).toContain(
"Error in tool 'errorTool': Test error",
);
}
});
});