File size: 911 Bytes
7421850
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
 * @license
 * Copyright 2026 Google LLC
 * SPDX-License-Identifier: Apache-2.0
 */

import { GeminiCliAgent, tool, z } from '../src/index.js';

async function main() {
  const myTool = tool(
    {
      name: 'add',
      description: 'Add two numbers.',
      inputSchema: z.object({
        a: z.number().describe('the first number'),
        b: z.number().describe('the second number'),
      }),
    },
    async ({ a, b }) => {
      console.log(`Tool 'add' called with a=${a}, b=${b}`);
      return { result: a + b };
    },
  );

  const agent = new GeminiCliAgent({
    instructions: 'Make sure to always talk like a pirate.',
    tools: [myTool],
  });

  console.log("Sending prompt: 'add 5 + 6'");
  for await (const chunk of agent.sendStream(
    'add 5 + 6 and tell me a story involving the result',
  )) {
    console.log(JSON.stringify(chunk, null, 2));
  }
}

main().catch(console.error);