99from __future__ import annotations
1010
1111import logging
12+ import os
1213from pathlib import Path
1314
15+ from a2a .types import AgentCard
1416from google .adk .agents import Agent
15- from google .adk .tools import tool_context
17+ from google .adk .tools import ToolContext
1618from kagent .adk import KAgentApp
17- from kagent .adk .types import AgentConfig
1819
1920logger = logging .getLogger (__name__ )
2021
2122SKILLS_DIR = Path (__file__ ).parent .parent / "skills"
2223
2324
24- @tool_context .tool
25- def calculate (expression : str ) -> str :
25+ def calculate (expression : str , tool_context : ToolContext ) -> str :
2626 """Evaluate a mathematical expression and return the result.
2727
2828 Args:
@@ -38,8 +38,7 @@ def calculate(expression: str) -> str:
3838 return f"Error calculating { expression } : { str (e )} "
3939
4040
41- @tool_context .tool
42- def get_weather (location : str ) -> str :
41+ def get_weather (location : str , tool_context : ToolContext ) -> str :
4342 """Get the current weather for a location.
4443
4544 Args:
@@ -76,32 +75,35 @@ def get_weather(location: str) -> str:
7675)
7776
7877
79- agent_config = AgentConfig ()
80-
81-
8278# Create KAgent app
79+ # Read agent name and kagent URL from environment when running inside kagent,
80+ # falling back to defaults for local development. Convert hyphens to underscores
81+ # for the ADK app_name (must be a valid Python identifier).
82+ _raw_name = os .getenv ("KAGENT_NAME" , "basic_anthropic_agent" )
83+ _app_name = _raw_name .replace ("-" , "_" )
84+ _kagent_url = os .getenv ("KAGENT_URL" , "http://localhost:8083" )
85+
8386app = KAgentApp (
8487 root_agent_factory = lambda : root_agent ,
85- agent_card = {
86- " name" : "basic-anthropic-agent" ,
87- " description" : "A basic Anthropic agent with calculator and weather tools" ,
88- " url" : "localhost:8000" ,
89- " version" : "0.1.0" ,
90- " capabilities" : {"streaming" : True },
91- " defaultInputModes" : ["text" ],
92- " defaultOutputModes" : ["text" ],
93- " skills" : [
88+ agent_card = AgentCard (
89+ name = "basic-anthropic-agent" ,
90+ description = "A basic Anthropic agent with calculator and weather tools" ,
91+ url = "localhost:8000" ,
92+ version = "0.1.0" ,
93+ capabilities = {"streaming" : True },
94+ defaultInputModes = ["text" ],
95+ defaultOutputModes = ["text" ],
96+ skills = [
9497 {
9598 "id" : "basic" ,
9699 "name" : "Basic Assistant" ,
97100 "description" : "Can perform calculations and get weather information" ,
98101 "tags" : ["calculator" , "weather" , "assistant" ],
99102 }
100103 ],
101- },
102- kagent_url = "http://localhost:8083" ,
103- app_name = "basic-anthropic-agent" ,
104- agent_config = agent_config ,
104+ ),
105+ kagent_url = _kagent_url ,
106+ app_name = _app_name ,
105107 stream = True ,
106108)
107109
0 commit comments