kagent-adk 0.6.19__py3-none-any.whl → 0.6.21__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of kagent-adk might be problematic. Click here for more details.
- kagent/adk/_a2a.py +62 -3
- kagent/adk/_agent_executor.py +19 -1
- kagent/adk/_session_service.py +2 -0
- kagent/adk/cli.py +11 -1
- kagent/adk/types.py +1 -1
- {kagent_adk-0.6.19.dist-info → kagent_adk-0.6.21.dist-info}/METADATA +4 -2
- {kagent_adk-0.6.19.dist-info → kagent_adk-0.6.21.dist-info}/RECORD +9 -9
- {kagent_adk-0.6.19.dist-info → kagent_adk-0.6.21.dist-info}/WHEEL +0 -0
- {kagent_adk-0.6.19.dist-info → kagent_adk-0.6.21.dist-info}/entry_points.txt +0 -0
kagent/adk/_a2a.py
CHANGED
|
@@ -7,10 +7,13 @@ from typing import Callable
|
|
|
7
7
|
import httpx
|
|
8
8
|
from a2a.server.apps import A2AFastAPIApplication
|
|
9
9
|
from a2a.server.request_handlers import DefaultRequestHandler
|
|
10
|
+
from a2a.server.tasks import InMemoryTaskStore
|
|
10
11
|
from a2a.types import AgentCard
|
|
12
|
+
from agentsts.adk import ADKRunner, ADKSessionService, ADKSTSIntegration, ADKTokenPropagationPlugin
|
|
11
13
|
from fastapi import FastAPI, Request
|
|
12
14
|
from fastapi.responses import PlainTextResponse
|
|
13
15
|
from google.adk.agents import BaseAgent
|
|
16
|
+
from google.adk.apps import App
|
|
14
17
|
from google.adk.runners import Runner
|
|
15
18
|
from google.adk.sessions import InMemorySessionService
|
|
16
19
|
from google.genai import types
|
|
@@ -21,7 +24,19 @@ from ._agent_executor import A2aAgentExecutor
|
|
|
21
24
|
from ._session_service import KAgentSessionService
|
|
22
25
|
from ._token import KAgentTokenService
|
|
23
26
|
|
|
27
|
+
|
|
24
28
|
# --- Configure Logging ---
|
|
29
|
+
def configure_logging() -> None:
|
|
30
|
+
"""Configure logging based on LOG_LEVEL environment variable."""
|
|
31
|
+
log_level = os.getenv("LOG_LEVEL", "INFO").upper()
|
|
32
|
+
numeric_level = getattr(logging, log_level, logging.INFO)
|
|
33
|
+
logging.basicConfig(
|
|
34
|
+
level=numeric_level,
|
|
35
|
+
)
|
|
36
|
+
logging.info(f"Logging configured with level: {log_level}")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
configure_logging()
|
|
25
40
|
logger = logging.getLogger(__name__)
|
|
26
41
|
|
|
27
42
|
|
|
@@ -39,6 +54,7 @@ def thread_dump(request: Request) -> PlainTextResponse:
|
|
|
39
54
|
|
|
40
55
|
|
|
41
56
|
kagent_url_override = os.getenv("KAGENT_URL")
|
|
57
|
+
sts_well_known_uri = os.getenv("STS_WELL_KNOWN_URI")
|
|
42
58
|
|
|
43
59
|
|
|
44
60
|
class KAgentApp:
|
|
@@ -61,10 +77,17 @@ class KAgentApp:
|
|
|
61
77
|
)
|
|
62
78
|
session_service = KAgentSessionService(http_client)
|
|
63
79
|
|
|
80
|
+
plugins = []
|
|
81
|
+
if sts_well_known_uri:
|
|
82
|
+
sts_integration = ADKSTSIntegration(sts_well_known_uri)
|
|
83
|
+
session_service = ADKSessionService(sts_integration, session_service)
|
|
84
|
+
plugins.append(ADKTokenPropagationPlugin(sts_integration))
|
|
85
|
+
|
|
86
|
+
adk_app = App(name=self.app_name, root_agent=self.root_agent, plugins=plugins)
|
|
87
|
+
|
|
64
88
|
def create_runner() -> Runner:
|
|
65
|
-
return
|
|
66
|
-
|
|
67
|
-
app_name=self.app_name,
|
|
89
|
+
return ADKRunner(
|
|
90
|
+
app=adk_app,
|
|
68
91
|
session_service=session_service,
|
|
69
92
|
)
|
|
70
93
|
|
|
@@ -96,6 +119,42 @@ class KAgentApp:
|
|
|
96
119
|
|
|
97
120
|
return app
|
|
98
121
|
|
|
122
|
+
def build_local(self) -> FastAPI:
|
|
123
|
+
session_service = InMemorySessionService()
|
|
124
|
+
|
|
125
|
+
def create_runner() -> Runner:
|
|
126
|
+
return Runner(
|
|
127
|
+
agent=self.root_agent,
|
|
128
|
+
app_name=self.app_name,
|
|
129
|
+
session_service=session_service,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
agent_executor = A2aAgentExecutor(
|
|
133
|
+
runner=create_runner,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
task_store = InMemoryTaskStore()
|
|
137
|
+
request_context_builder = KAgentRequestContextBuilder(task_store=task_store)
|
|
138
|
+
request_handler = DefaultRequestHandler(
|
|
139
|
+
agent_executor=agent_executor,
|
|
140
|
+
task_store=task_store,
|
|
141
|
+
request_context_builder=request_context_builder,
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
a2a_app = A2AFastAPIApplication(
|
|
145
|
+
agent_card=self.agent_card,
|
|
146
|
+
http_handler=request_handler,
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
faulthandler.enable()
|
|
150
|
+
app = FastAPI()
|
|
151
|
+
|
|
152
|
+
app.add_route("/health", methods=["GET"], route=health_check)
|
|
153
|
+
app.add_route("/thread_dump", methods=["GET"], route=thread_dump)
|
|
154
|
+
a2a_app.add_routes_to_app(app)
|
|
155
|
+
|
|
156
|
+
return app
|
|
157
|
+
|
|
99
158
|
async def test(self, task: str):
|
|
100
159
|
session_service = InMemorySessionService()
|
|
101
160
|
SESSION_ID = "12345"
|
kagent/adk/_agent_executor.py
CHANGED
|
@@ -156,6 +156,10 @@ class A2aAgentExecutor(AgentExecutor):
|
|
|
156
156
|
# Convert the a2a request to ADK run args
|
|
157
157
|
run_args = convert_a2a_request_to_adk_run_args(context)
|
|
158
158
|
|
|
159
|
+
# set request headers to session state
|
|
160
|
+
headers = context.call_context.state.get("headers", {})
|
|
161
|
+
run_args["headers"] = headers
|
|
162
|
+
|
|
159
163
|
# ensure the session exists
|
|
160
164
|
session = await self._prepare_session(context, run_args, runner)
|
|
161
165
|
|
|
@@ -256,12 +260,26 @@ class A2aAgentExecutor(AgentExecutor):
|
|
|
256
260
|
session_id=session_id,
|
|
257
261
|
)
|
|
258
262
|
if session is None:
|
|
263
|
+
# Extract session name from the first TextPart (like the UI does)
|
|
264
|
+
session_name = None
|
|
265
|
+
if context.message and context.message.parts:
|
|
266
|
+
for part in context.message.parts:
|
|
267
|
+
# A2A parts have a .root property that contains the actual part (TextPart, FilePart, etc.)
|
|
268
|
+
if isinstance(part, Part):
|
|
269
|
+
root_part = part.root
|
|
270
|
+
if isinstance(root_part, TextPart) and root_part.text:
|
|
271
|
+
# Take first 20 chars + "..." if longer (matching UI behavior)
|
|
272
|
+
text = root_part.text.strip()
|
|
273
|
+
session_name = text[:20] + ("..." if len(text) > 20 else "")
|
|
274
|
+
break
|
|
275
|
+
|
|
259
276
|
session = await runner.session_service.create_session(
|
|
260
277
|
app_name=runner.app_name,
|
|
261
278
|
user_id=user_id,
|
|
262
|
-
state={},
|
|
279
|
+
state={"session_name": session_name},
|
|
263
280
|
session_id=session_id,
|
|
264
281
|
)
|
|
282
|
+
|
|
265
283
|
# Update run_args with the new session_id
|
|
266
284
|
run_args["session_id"] = session.id
|
|
267
285
|
|
kagent/adk/_session_service.py
CHANGED
|
@@ -40,6 +40,8 @@ class KAgentSessionService(BaseSessionService):
|
|
|
40
40
|
}
|
|
41
41
|
if session_id:
|
|
42
42
|
request_data["id"] = session_id
|
|
43
|
+
if state and state.get("session_name"):
|
|
44
|
+
request_data["name"] = state.get("session_name", "")
|
|
43
45
|
|
|
44
46
|
# Make API call to create session
|
|
45
47
|
response = await self.client.post(
|
kagent/adk/cli.py
CHANGED
|
@@ -57,6 +57,9 @@ def run(
|
|
|
57
57
|
host: str = "127.0.0.1",
|
|
58
58
|
port: int = 8080,
|
|
59
59
|
workers: int = 1,
|
|
60
|
+
local: Annotated[
|
|
61
|
+
bool, typer.Option("--local", help="Run with in-memory session service (for local development)")
|
|
62
|
+
] = False,
|
|
60
63
|
):
|
|
61
64
|
app_cfg = KAgentConfig()
|
|
62
65
|
|
|
@@ -66,8 +69,15 @@ def run(
|
|
|
66
69
|
with open(os.path.join(working_dir, name, "agent-card.json"), "r") as f:
|
|
67
70
|
agent_card = json.load(f)
|
|
68
71
|
agent_card = AgentCard.model_validate(agent_card)
|
|
72
|
+
|
|
69
73
|
kagent_app = KAgentApp(root_agent, agent_card, app_cfg.url, app_cfg.app_name)
|
|
70
|
-
|
|
74
|
+
|
|
75
|
+
if local:
|
|
76
|
+
logger.info("Running in local mode with InMemorySessionService")
|
|
77
|
+
server = kagent_app.build_local()
|
|
78
|
+
else:
|
|
79
|
+
server = kagent_app.build()
|
|
80
|
+
|
|
71
81
|
configure_tracing(server)
|
|
72
82
|
|
|
73
83
|
uvicorn.run(
|
kagent/adk/types.py
CHANGED
|
@@ -101,7 +101,7 @@ class AgentConfig(BaseModel):
|
|
|
101
101
|
for http_tool in self.http_tools: # add http tools
|
|
102
102
|
tools.append(MCPToolset(connection_params=http_tool.params, tool_filter=http_tool.tools))
|
|
103
103
|
if self.sse_tools:
|
|
104
|
-
for sse_tool in self.sse_tools: # add
|
|
104
|
+
for sse_tool in self.sse_tools: # add sse tools
|
|
105
105
|
tools.append(MCPToolset(connection_params=sse_tool.params, tool_filter=sse_tool.tools))
|
|
106
106
|
if self.remote_agents:
|
|
107
107
|
for remote_agent in self.remote_agents: # Add remote agents as tools
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: kagent-adk
|
|
3
|
-
Version: 0.6.
|
|
3
|
+
Version: 0.6.21
|
|
4
4
|
Summary: kagent-adk is an sdk for integrating adk agents with kagent
|
|
5
|
-
Requires-Python: >=3.
|
|
5
|
+
Requires-Python: >=3.11.0
|
|
6
6
|
Requires-Dist: a2a-sdk>=0.3.1
|
|
7
|
+
Requires-Dist: agentsts-adk>=0.0.5
|
|
8
|
+
Requires-Dist: agentsts-core>=0.0.5
|
|
7
9
|
Requires-Dist: aiofiles>=24.1.0
|
|
8
10
|
Requires-Dist: anthropic[vertex]>=0.49.0
|
|
9
11
|
Requires-Dist: anyio>=4.9.0
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
kagent/adk/__init__.py,sha256=Cam9hwhl6Z1tZ3WJIB1KATX24MwRMpiyBLYF64DTqQI,182
|
|
2
|
-
kagent/adk/_a2a.py,sha256=
|
|
3
|
-
kagent/adk/_agent_executor.py,sha256=
|
|
4
|
-
kagent/adk/_session_service.py,sha256=
|
|
2
|
+
kagent/adk/_a2a.py,sha256=B1ZiVFJHNJyJ_6HsCbAG5w5-wF9xrNKhr3-ok9CCick,6424
|
|
3
|
+
kagent/adk/_agent_executor.py,sha256=3aFMR41FwluDZZJGkpsL4yhz7JgqTTSbKtLeENrr0TE,11090
|
|
4
|
+
kagent/adk/_session_service.py,sha256=7o2T4-572hAvpD3KZQn1ExPvI67aEuLcyHqQXB3b2JI,5757
|
|
5
5
|
kagent/adk/_token.py,sha256=OL46m7U5vUTby1WWjVB7Jqzig4TWddzoAmLVLlfSdAg,2515
|
|
6
|
-
kagent/adk/cli.py,sha256=
|
|
7
|
-
kagent/adk/types.py,sha256=
|
|
6
|
+
kagent/adk/cli.py,sha256=_yluK6p7sbUld5juWCyIu3E8U1_Zys7eWxBabcHXXIo,3251
|
|
7
|
+
kagent/adk/types.py,sha256=kcNpRwo6XcfMtgsOchgDuslYjMY-7pSlVnglihoUKss,5685
|
|
8
8
|
kagent/adk/converters/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
9
9
|
kagent/adk/converters/error_mappings.py,sha256=1KUJPS8VrcaTv6yUKb5Whg-S2XX8YGJmtTIeZqnqvuw,2769
|
|
10
10
|
kagent/adk/converters/event_converter.py,sha256=WKQRqREB11TbgGp6U_--mmukvJJgew6-VEkrGBqGVA4,10519
|
|
@@ -12,7 +12,7 @@ kagent/adk/converters/part_converter.py,sha256=8Ej9xGRYW8YoPnExGDnEUw1beurCfkNhA
|
|
|
12
12
|
kagent/adk/converters/request_converter.py,sha256=iTmTmhlnyRfuYyFi4WmpTSXPz22xjjotbe750j-CvYA,1072
|
|
13
13
|
kagent/adk/models/__init__.py,sha256=mqD0JhS9kT1rMpFNLq5-qnjstpp6lzT9xADaOfjrUKY,78
|
|
14
14
|
kagent/adk/models/_openai.py,sha256=EpZTqxAEaKhgi-98sqyQhArckWwoGh-C34fC8MyClHk,17187
|
|
15
|
-
kagent_adk-0.6.
|
|
16
|
-
kagent_adk-0.6.
|
|
17
|
-
kagent_adk-0.6.
|
|
18
|
-
kagent_adk-0.6.
|
|
15
|
+
kagent_adk-0.6.21.dist-info/METADATA,sha256=oPN2egxeoRZpz_hOoBSH1f8GgDSjRbe6pczg3UhfiSc,1014
|
|
16
|
+
kagent_adk-0.6.21.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
17
|
+
kagent_adk-0.6.21.dist-info/entry_points.txt,sha256=a1Q2Inc9L0dvXWEkwnCdf9cfXdpX5Dl2Q6DhNWNjhxw,50
|
|
18
|
+
kagent_adk-0.6.21.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|