11import { LlmAgent as Agent } from 'adk-typescript/agents' ;
22import { LlmRegistry } from 'adk-typescript/models' ;
3- import { ToolContext } from 'adk-typescript/tools' ;
3+ import { ToolContext , FunctionTool } from 'adk-typescript/tools' ;
44import { runAgent } from 'adk-typescript' ;
55
66// --- Tool Functions ---
77
88/**
99 * Returns current weather information for a specified city
10- * @param city Name of the city to get weather for
10+ * @param params Tool parameters object containing city
1111 * @param context Optional ToolContext
1212 * @returns Promise resolving to weather information or error
1313 */
1414async function getWeather (
15- city : string ,
15+ params : Record < string , any > ,
1616 context : ToolContext
1717) : Promise < { status : string ; report ?: string ; error_message ?: string } > {
18+ const city = params . city ;
1819 console . log ( `--- Tool: getWeather called for city: ${ city } ---` ) ;
1920 const cityNormalized = city . toLowerCase ( ) . trim ( ) ;
2021 const mockWeatherDb : Record < string , { status : string ; report : string } > = {
@@ -28,10 +29,12 @@ async function getWeather(
2829
2930/**
3031 * Gets the current local time and timezone.
32+ * @param params Tool parameters object (no parameters needed)
3133 * @param context Optional ToolContext
3234 * @returns Promise resolving to time information
3335 */
3436async function getCurrentTime (
37+ params : Record < string , any > ,
3538 context : ToolContext
3639) : Promise < { currentTime : string ; timezone : string ; } > {
3740 console . log ( `--- Tool: getCurrentTime called ---` ) ;
@@ -44,19 +47,51 @@ async function getCurrentTime(
4447
4548// --- Agent Definition ---
4649
47- // Use LlmRegistry to get a model instance
48- const agentLlm = LlmRegistry . newLlm ( "gemini-2.0-flash" ) ; // Or another compatible model
50+ // Create tools with explicit function declarations
51+ const getWeatherTool = new FunctionTool ( {
52+ name : 'getWeather' ,
53+ description : 'Returns current weather information for a specified city' ,
54+ fn : getWeather ,
55+ functionDeclaration : {
56+ name : 'getWeather' ,
57+ description : 'Returns current weather information for a specified city' ,
58+ parameters : {
59+ type : 'object' ,
60+ properties : {
61+ city : {
62+ type : 'string' ,
63+ description : 'Name of the city to get weather for'
64+ }
65+ } ,
66+ required : [ 'city' ]
67+ }
68+ }
69+ } ) ;
70+
71+ const getCurrentTimeTool = new FunctionTool ( {
72+ name : 'getCurrentTime' ,
73+ description : 'Gets the current local time and timezone' ,
74+ fn : getCurrentTime ,
75+ functionDeclaration : {
76+ name : 'getCurrentTime' ,
77+ description : 'Gets the current local time and timezone' ,
78+ parameters : {
79+ type : 'object' ,
80+ properties : { } ,
81+ required : [ ]
82+ }
83+ }
84+ } ) ;
4985
5086// Export the root agent for ADK tools to find
51- // Now we can pass functions directly to the tools array!
5287export const rootAgent = new Agent ( {
5388 name : "default_agent" , // Unique agent name
54- model : agentLlm , // LLM instance
89+ model : "gemini-2.0-flash" ,
5590 description : "Provides current weather and time information for cities." ,
5691 instruction : "You are a helpful assistant. Use the 'getWeather' tool for weather queries " +
5792 "and the 'getCurrentTime' tool for time queries. Provide clear answers based on tool results. " +
5893 "If asked for weather AND time, use both tools." ,
59- tools : [ getWeather , getCurrentTime ] , // Functions can now be passed directly!
94+ tools : [ getWeatherTool , getCurrentTimeTool ] ,
6095} ) ;
6196
6297// Run agent directly when this file is executed
0 commit comments