Skip to content

Commit 0468bc5

Browse files
committed
update uv loc
Signed-off-by: dongjiang <dongjiang1989@126.com>
1 parent b657700 commit 0468bc5

2 files changed

Lines changed: 40 additions & 22 deletions

File tree

python/samples/anthropic/basic_agent/basic_agent/agent.py

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,20 @@
99
from __future__ import annotations
1010

1111
import logging
12+
import os
1213
from pathlib import Path
1314

15+
from a2a.types import AgentCard
1416
from google.adk.agents import Agent
15-
from google.adk.tools import tool_context
17+
from google.adk.tools import ToolContext
1618
from kagent.adk import KAgentApp
17-
from kagent.adk.types import AgentConfig
1819

1920
logger = logging.getLogger(__name__)
2021

2122
SKILLS_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+
8386
app = 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

python/uv.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)