Skip to content

Commit 6ece22d

Browse files
Merge pull request #50 from dnlrbz:chore/typos-and-tests
PiperOrigin-RevId: 853306331
2 parents 4bded65 + ea1078e commit 6ece22d

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

core/src/tools/agent_tool.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,12 +147,12 @@ export class AgentTool extends BaseTool {
147147
const hasOutputSchema =
148148
this.agent instanceof LlmAgent && this.agent.outputSchema;
149149

150-
const mergetText = lastEvent.content.parts.map((part) => part.text)
150+
const mergedText = lastEvent.content.parts.map((part) => part.text)
151151
.filter((text) => text)
152152
.join('\n');
153153

154154
// TODO - b/425992518: In case of output schema, the output should be
155155
// validated. Consider similar logic to one we have in Python ADK.
156-
return hasOutputSchema ? JSON.parse(mergetText) : mergetText;
156+
return hasOutputSchema ? JSON.parse(mergedText) : mergedText;
157157
}
158158
}

core/src/tools/tool_confirmation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export class ToolConfirmation {
1212
/** The hint text for why the input is needed. */
1313
hint: string;
1414

15-
/** Whether the tool excution is confirmed. */
15+
/** Whether the tool execution is confirmed. */
1616
confirmed: boolean;
1717

1818
/**
@@ -33,4 +33,4 @@ export class ToolConfirmation {
3333
this.confirmed = confirmed;
3434
this.payload = payload;
3535
}
36-
}
36+
}

core/test/tools/function_tool_test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,4 +199,25 @@ describe('FunctionTool', () => {
199199
});
200200
expect(result).toEqual(3);
201201
});
202+
203+
it('wraps errors from execute function', async () => {
204+
const tool = new FunctionTool({
205+
name: 'errorTool',
206+
description: 'Throws an error.',
207+
parameters: z.object({}),
208+
execute: async () => {
209+
throw new Error('Test error');
210+
},
211+
});
212+
try {
213+
await tool.runAsync({
214+
args: {},
215+
toolContext: emptyContext,
216+
});
217+
} catch (e) {
218+
expect((e as Error).message).toContain(
219+
"Error in tool 'errorTool': Test error",
220+
);
221+
}
222+
});
202223
});

0 commit comments

Comments
 (0)