elan-agentkit-runtime 0.2.4__tar.gz → 0.2.6__tar.gz
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.
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/CHANGELOG.md +33 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/PKG-INFO +3 -3
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/pyproject.toml +6 -5
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/builder.py +418 -45
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/connections.py +11 -1
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/engine.py +20 -3
- elan_agentkit_runtime-0.2.6/src/agentkit_runtime/graph_export.py +131 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/manifest_export.py +41 -4
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/plugins.py +43 -14
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/security.py +7 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/.gitignore +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/LICENSE +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/README.md +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/__init__.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/concurrency.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/config.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/consumer.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/fleet.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/main.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/pubsub_push.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/registry.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/schema_export.py +0 -0
- {elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/tenant_plugins.py +0 -0
|
@@ -3,6 +3,39 @@
|
|
|
3
3
|
Versions follow the tag that published them — `runtime/v*`. A version with no
|
|
4
4
|
date has not been published yet.
|
|
5
5
|
|
|
6
|
+
## 0.2.6 — 2026-11-28
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- `MANIFEST.context_cache` reaches `App(context_cache_config=...)` (ADR-0272), which also answers ADK's once-per-pod warning about an app whose agents transfer with no context cache.
|
|
11
|
+
- `workflow` and `agent` tool bindings (ADR-0269): `ctx.tools()` builds each as one tool over the sibling target's own `build()` — `WorkflowTool` for a workflow, ADK's `AgentTool` for an agent — named after the slug. `ctx.agent_tool(slug)` joins `ctx.workflow_tool(slug)` as the code path. A cycle is refused naming the chain, and the wrong kind is refused naming the right binding.
|
|
12
|
+
- `WorkflowResultPlugin`, installed on every App: a workflow called as a tool hands its caller its TERMINAL OUTPUT — JSON for a structure, the text for a string — rather than whichever model node spoke last. A terminal node that already produced content is untouched.
|
|
13
|
+
- The caller's credential service declares the union of its own and every bound callee's `credentials`, so a callee's tools are not refused names only the callee declared.
|
|
14
|
+
- A bound workflow or agent is charged its OWN manifest's token prices for its nested run, unless the caller names one of its agents in `agent_token_costs` (ADR-0270). `build_plugins` passes the target's per-agent prices and every bound target's to the ledger plugin, and the pod warns at startup about a price on an agent name nothing it builds is called.
|
|
15
|
+
|
|
16
|
+
### Changed
|
|
17
|
+
|
|
18
|
+
- **A nested run includes the platform's plugins** (ADR-0268): `workflow_tool` no longer passes `include_plugins=False`, so the nested workflow's model calls are billed against the caller's hold and counted. An `AgentTool` built with `include_plugins=False` anywhere in a target is logged as an error at startup, naming it.
|
|
19
|
+
- A workflow called as a tool now gets its manifest's `nodes` overrides and `max_concurrency`, as it does when launched.
|
|
20
|
+
- The startup warning that a price on a nested agent's tool "will never be charged" is gone: it is charged now.
|
|
21
|
+
- The MCP gateway header carries the envelope's invocation id inside a nested run, not the nested runner's own.
|
|
22
|
+
- Requires `elan-agentkit-core>=0.2.6` and `elan-agentkit-plugins>=0.1.3`.
|
|
23
|
+
|
|
24
|
+
## 0.2.5 — 2026-11-25
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- A workflow run's `started` event carries the workflow's topology as `payload.graph` — every node with its type (`agent`, `function`, `join`, `workflow`, `tool`), an agent node's model, the manifest's timeout and retry overrides, and every edge with its route — from `agentkit_runtime.graph_export.describe`, serialised once at pod start (ADR-0264). An agent's `started` payload is unchanged.
|
|
29
|
+
- The manifest exporter adds the same `graph` to a workflow's exported manifest, so a deploy can record it. Best-effort: a `build()` that fails here is reported on stderr and never fails the export.
|
|
30
|
+
|
|
31
|
+
### Fixed
|
|
32
|
+
|
|
33
|
+
- A connected account's granted scopes are split on commas as well as spaces. GitHub reports them as `read:user,repo`, which was stored as a single scope.
|
|
34
|
+
|
|
35
|
+
### Changed
|
|
36
|
+
|
|
37
|
+
- Requires `elan-agentkit-plugins>=0.1.2`, the version that refuses an MCP tool call a person rejected. pip's default upgrade keeps a dependency that still satisfies its floor, so under `>=0.1.1` an upgrade of this package alone kept the plugin that let the call run.
|
|
38
|
+
|
|
6
39
|
## 0.2.4 — 2026-11-20
|
|
7
40
|
|
|
8
41
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: elan-agentkit-runtime
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: The single container that runs any agent or workflow, selected by TARGET_SLUG
|
|
5
5
|
Project-URL: Homepage, https://openelan.ai
|
|
6
6
|
Project-URL: Documentation, https://openelan.ai/app/docs
|
|
@@ -16,8 +16,8 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
16
16
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
17
17
|
Requires-Python: >=3.12
|
|
18
18
|
Requires-Dist: asyncpg>=0.30
|
|
19
|
-
Requires-Dist: elan-agentkit-core>=0.2.
|
|
20
|
-
Requires-Dist: elan-agentkit-plugins>=0.1.
|
|
19
|
+
Requires-Dist: elan-agentkit-core>=0.2.6
|
|
20
|
+
Requires-Dist: elan-agentkit-plugins>=0.1.3
|
|
21
21
|
Requires-Dist: fastapi>=0.115
|
|
22
22
|
Requires-Dist: google-adk<3,>=2.8.0
|
|
23
23
|
Requires-Dist: google-auth>=2.35
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "elan-agentkit-runtime"
|
|
3
|
-
version = "0.2.
|
|
3
|
+
version = "0.2.6"
|
|
4
4
|
description = "The single container that runs any agent or workflow, selected by TARGET_SLUG"
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.12"
|
|
@@ -19,10 +19,11 @@ classifiers = [
|
|
|
19
19
|
dependencies = [
|
|
20
20
|
# FLOORS, NOT NAMES. This version imports `agentkit_core.connections` and
|
|
21
21
|
# `Credentials.connections` from core 0.2.4 (ADR-0260), so an install that
|
|
22
|
-
# kept an older core would fail at import
|
|
23
|
-
#
|
|
24
|
-
|
|
25
|
-
"elan-agentkit-
|
|
22
|
+
# kept an older core would fail at import. plugins 0.1.2 is the one that
|
|
23
|
+
# refuses an MCP call a person REJECTED (0.1.1 let it run), and pip's
|
|
24
|
+
# default upgrade keeps a dependency that still satisfies its floor.
|
|
25
|
+
"elan-agentkit-core>=0.2.6",
|
|
26
|
+
"elan-agentkit-plugins>=0.1.3",
|
|
26
27
|
"google-adk>=2.8.0,<3",
|
|
27
28
|
# PINNED <2. google-adk 2.8's mcp_tool package wraps its imports in a
|
|
28
29
|
# try/except, so against mcp 2.x McpToolset simply does not exist and the
|
|
@@ -8,11 +8,14 @@ This module is the only place that branches on ``kind``.
|
|
|
8
8
|
|
|
9
9
|
from __future__ import annotations
|
|
10
10
|
|
|
11
|
+
import json
|
|
11
12
|
import logging
|
|
12
13
|
import os
|
|
14
|
+
from contextvars import ContextVar
|
|
13
15
|
from dataclasses import dataclass
|
|
14
16
|
from typing import Any
|
|
15
17
|
|
|
18
|
+
from agentkit_core.context import TargetPrices, current_invocation, priced_as
|
|
16
19
|
from agentkit_core.identity import (
|
|
17
20
|
INVOCATION_HEADER,
|
|
18
21
|
SUBJECT_HEADER,
|
|
@@ -20,10 +23,18 @@ from agentkit_core.identity import (
|
|
|
20
23
|
mcp_path,
|
|
21
24
|
mcp_public_url,
|
|
22
25
|
)
|
|
23
|
-
from agentkit_core.manifest import
|
|
26
|
+
from agentkit_core.manifest import (
|
|
27
|
+
BaseTargetManifest,
|
|
28
|
+
Credentials,
|
|
29
|
+
ToolBinding,
|
|
30
|
+
WorkflowManifest,
|
|
31
|
+
target_tool_name,
|
|
32
|
+
)
|
|
24
33
|
from agentkit_core.service_auth import ProjectedToken
|
|
34
|
+
from agentkit_plugins.nesting import RUNS_NESTED
|
|
25
35
|
from google.adk.apps import App
|
|
26
36
|
from google.adk.apps._configs import EventsCompactionConfig, ResumabilityConfig
|
|
37
|
+
from google.adk.plugins.base_plugin import BasePlugin
|
|
27
38
|
from google.adk.tools.agent_tool import AgentTool
|
|
28
39
|
|
|
29
40
|
from agentkit_runtime.config import Settings
|
|
@@ -120,11 +131,27 @@ def _declare_connections(manifest: Any) -> None:
|
|
|
120
131
|
declare_connections(getattr(credentials, "connections", None))
|
|
121
132
|
|
|
122
133
|
|
|
123
|
-
def build_tools(manifest: BaseTargetManifest
|
|
124
|
-
|
|
134
|
+
def build_tools(manifest: BaseTargetManifest, settings: Settings | None = None,
|
|
135
|
+
*, callers: tuple[str, ...] = ()) -> list[Any]:
|
|
136
|
+
"""Turn the manifest's tool bindings into ADK tools and toolsets.
|
|
137
|
+
|
|
138
|
+
`settings` is needed only by a `workflow` or `agent` binding, which builds
|
|
139
|
+
a sibling target (ADR-0269); `callers` is the chain of targets whose tools
|
|
140
|
+
are being built that led here, so a cycle is refused by name instead of
|
|
141
|
+
recursing until the interpreter gives up.
|
|
142
|
+
"""
|
|
125
143
|
tools: list[Any] = []
|
|
126
144
|
|
|
127
145
|
for binding in getattr(manifest, "tools", []):
|
|
146
|
+
if binding.names_a_target:
|
|
147
|
+
if settings is None:
|
|
148
|
+
raise ValueError(
|
|
149
|
+
f"{manifest.slug}: tool {binding.ref!r} is a {binding.kind} "
|
|
150
|
+
"binding, which needs the runtime's settings to resolve")
|
|
151
|
+
chain = (*callers, manifest.slug)
|
|
152
|
+
build = workflow_tool if binding.kind == "workflow" else agent_tool
|
|
153
|
+
tools.append(build(binding.ref, settings, callers=chain))
|
|
154
|
+
continue
|
|
128
155
|
if binding.kind != "mcp":
|
|
129
156
|
raise ValueError(
|
|
130
157
|
f"{manifest.slug}: tool kind {binding.kind!r} is not supported yet"
|
|
@@ -211,7 +238,13 @@ def gateway_header_provider(inner: Any = None) -> Any:
|
|
|
211
238
|
token = _WORKLOAD_TOKEN.read()
|
|
212
239
|
if token:
|
|
213
240
|
headers[WORKLOAD_TOKEN_HEADER] = token
|
|
214
|
-
|
|
241
|
+
# THE ENVELOPE'S INVOCATION, NOT ADK'S. They are the same id for a
|
|
242
|
+
# top-level run; inside a nested one (ADR-0268) ADK's is the nested
|
|
243
|
+
# runner's own `e-<uuid>`, which names nothing the gateway or the
|
|
244
|
+
# ledger has ever heard of.
|
|
245
|
+
envelope = current_invocation()
|
|
246
|
+
invocation = (envelope.invocation_id if envelope is not None else
|
|
247
|
+
getattr(readonly_context, "invocation_id", "") or "")
|
|
215
248
|
user = getattr(readonly_context, "user_id", "") or ""
|
|
216
249
|
if invocation:
|
|
217
250
|
headers[INVOCATION_HEADER] = invocation
|
|
@@ -240,19 +273,100 @@ def your_credential_service(target: Any) -> Any:
|
|
|
240
273
|
what="credentials.service")
|
|
241
274
|
|
|
242
275
|
|
|
243
|
-
def credential_service_for(target: Any) -> Any:
|
|
276
|
+
def credential_service_for(target: Any, settings: Settings | None = None) -> Any:
|
|
244
277
|
"""The runner's credential service: `ElanCredentialService`, configured by
|
|
245
278
|
the manifest's `credentials` block (ADR-0249).
|
|
246
279
|
|
|
247
280
|
YOURS GOES BEHIND, NEVER IN FRONT. The platform's answers every `caller`
|
|
248
281
|
and `own` name and hands the rest to `credentials.service`, so a developer's
|
|
249
282
|
service can neither see a caller's token nor be asked to store one.
|
|
283
|
+
|
|
284
|
+
WITH `settings`, THE DECLARATIONS OF EVERY BOUND CALLEE TOO (ADR-0269). A
|
|
285
|
+
sibling target called as a tool runs on THIS runner, so its tools look up
|
|
286
|
+
their credentials here — and a name only the callee declared would
|
|
287
|
+
otherwise be refused as undeclared.
|
|
250
288
|
"""
|
|
251
289
|
from agentkit_runtime.security import ElanCredentialService # noqa: PLC0415
|
|
252
290
|
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
291
|
+
declared = (declared_credentials(target.manifest, settings)
|
|
292
|
+
if settings is not None else
|
|
293
|
+
getattr(target.manifest, "credentials", None))
|
|
294
|
+
return ElanCredentialService(your_credential_service(target), declared=declared)
|
|
295
|
+
|
|
296
|
+
|
|
297
|
+
def bound_targets(manifest: BaseTargetManifest, settings: Settings) -> list[Target]:
|
|
298
|
+
"""Every target this one binds as a tool, directly or through a callee.
|
|
299
|
+
|
|
300
|
+
In binding order, each once. A cycle is not refused here — `build_tools`
|
|
301
|
+
refuses it with the chain spelled out — so this only has to terminate.
|
|
302
|
+
"""
|
|
303
|
+
from agentkit_runtime.registry import discover # noqa: PLC0415
|
|
304
|
+
|
|
305
|
+
found: dict[str, Target] = {}
|
|
306
|
+
targets: dict[str, Target] | None = None
|
|
307
|
+
pending = [manifest]
|
|
308
|
+
while pending:
|
|
309
|
+
current = pending.pop(0)
|
|
310
|
+
for binding in getattr(current, "tools", []) or []:
|
|
311
|
+
if not binding.names_a_target or binding.ref in found \
|
|
312
|
+
or binding.ref == manifest.slug:
|
|
313
|
+
continue
|
|
314
|
+
if targets is None:
|
|
315
|
+
targets = discover(settings)
|
|
316
|
+
callee = targets.get(binding.ref)
|
|
317
|
+
if callee is None:
|
|
318
|
+
continue
|
|
319
|
+
found[binding.ref] = callee
|
|
320
|
+
pending.append(callee.manifest)
|
|
321
|
+
return list(found.values())
|
|
322
|
+
|
|
323
|
+
|
|
324
|
+
def declared_credentials(manifest: BaseTargetManifest,
|
|
325
|
+
settings: Settings) -> Credentials | None:
|
|
326
|
+
"""This target's `credentials`, widened by every bound callee's.
|
|
327
|
+
|
|
328
|
+
A NAME DECLARED TWICE MUST MEAN ONE THING. Two targets reading the same
|
|
329
|
+
`own` name from different variables would leave the callee's tool holding
|
|
330
|
+
whichever the merge kept, so that is refused rather than resolved. A
|
|
331
|
+
callee's own `credentials.service` is not composed: one runner has one, and
|
|
332
|
+
it is the caller's. The deploy cross-check refuses both before a pod starts.
|
|
333
|
+
"""
|
|
334
|
+
own = getattr(manifest, "credentials", None)
|
|
335
|
+
callees = [t.manifest for t in bound_targets(manifest, settings)]
|
|
336
|
+
if not any(getattr(m, "credentials", None) for m in callees):
|
|
337
|
+
return own
|
|
338
|
+
|
|
339
|
+
caller: list[str] = list(own.caller) if own else []
|
|
340
|
+
own_env = dict(own.own) if own else {}
|
|
341
|
+
connections: list[str] = list(own.connections) if own else []
|
|
342
|
+
for callee in callees:
|
|
343
|
+
declared = getattr(callee, "credentials", None)
|
|
344
|
+
if declared is None:
|
|
345
|
+
continue
|
|
346
|
+
caller += [name for name in declared.caller if name not in caller]
|
|
347
|
+
connections += [name for name in declared.connections
|
|
348
|
+
if name not in connections]
|
|
349
|
+
for name, source in declared.own.items():
|
|
350
|
+
if name in own_env and own_env[name] != source:
|
|
351
|
+
raise ValueError(
|
|
352
|
+
f"{manifest.slug} and {callee.slug}, which it calls as a "
|
|
353
|
+
f"tool, both declare the credential {name!r} and read it "
|
|
354
|
+
"from different places. They run in one pod, so the name "
|
|
355
|
+
"must mean one thing: rename one of them.")
|
|
356
|
+
own_env[name] = source
|
|
357
|
+
return Credentials(caller=caller, own=own_env, connections=connections,
|
|
358
|
+
service=own.service if own else None)
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
#: The workflow a `WorkflowTool` is running right now, by its root's name.
|
|
362
|
+
#:
|
|
363
|
+
#: SET AROUND THE NESTED RUN BY THE TOOL ITSELF, so `WorkflowResultPlugin` can
|
|
364
|
+
#: tell "this workflow's terminal output, on its way back to a caller" from
|
|
365
|
+
#: the same event in a workflow launched on its own — where giving it content
|
|
366
|
+
#: would print the output into the chat. A contextvar because the nested runner
|
|
367
|
+
#: runs inside the tool's own task, and ADK's node tasks copy it on creation.
|
|
368
|
+
_WORKFLOW_TOOL_ROOT: ContextVar[str | None] = ContextVar(
|
|
369
|
+
"workflow_tool_root", default=None)
|
|
256
370
|
|
|
257
371
|
|
|
258
372
|
class WorkflowTool(AgentTool):
|
|
@@ -298,27 +412,142 @@ class WorkflowTool(AgentTool):
|
|
|
298
412
|
declaration.description = self.agent.description or self.agent.name
|
|
299
413
|
return declaration
|
|
300
414
|
|
|
415
|
+
async def run_async(self, *, args: dict[str, Any], tool_context: Any) -> Any:
|
|
416
|
+
"""ADK's run, with this workflow marked as the one answering a caller
|
|
417
|
+
and its own prices bound (ADR-0270).
|
|
301
418
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
419
|
+
Everything else is inherited — the nested runner, the forwarded state
|
|
420
|
+
and artifacts, the caller's run config and plugins (ADR-0268).
|
|
421
|
+
"""
|
|
422
|
+
token = _WORKFLOW_TOOL_ROOT.set(self.agent.name)
|
|
423
|
+
try:
|
|
424
|
+
with priced_as(getattr(self, "target_prices", None)):
|
|
425
|
+
return await super().run_async(args=args, tool_context=tool_context)
|
|
426
|
+
finally:
|
|
427
|
+
_WORKFLOW_TOOL_ROOT.reset(token)
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
class TargetAgentTool(AgentTool):
|
|
431
|
+
"""A sibling AGENT bound as a tool: ADK's `AgentTool`, with the bound
|
|
432
|
+
target's own prices in force for its nested run (ADR-0270)."""
|
|
433
|
+
|
|
434
|
+
async def run_async(self, *, args: dict[str, Any], tool_context: Any) -> Any:
|
|
435
|
+
with priced_as(getattr(self, "target_prices", None)):
|
|
436
|
+
return await super().run_async(args=args, tool_context=tool_context)
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
def prices_of(manifest: BaseTargetManifest) -> TargetPrices:
|
|
440
|
+
"""A target's token prices as its manifest declares them (ADR-0270)."""
|
|
441
|
+
billing = manifest.billing
|
|
442
|
+
flat = billing.micros_per_mtok()
|
|
443
|
+
return TargetPrices(slug=manifest.slug,
|
|
444
|
+
flat=flat if flat.any_priced else None,
|
|
445
|
+
by_agent=billing.micros_per_mtok_by_agent())
|
|
446
|
+
|
|
447
|
+
|
|
448
|
+
class WorkflowResultPlugin(BasePlugin):
|
|
449
|
+
"""A workflow's terminal OUTPUT becomes the answer its caller receives.
|
|
450
|
+
|
|
451
|
+
ADK's `AgentTool` returns the LAST CONTENT a nested run produced. A
|
|
452
|
+
workflow's last node is usually a FunctionNode, whose return value rides
|
|
453
|
+
`Event(output=...)` with no content at all — so the caller was handed the
|
|
454
|
+
prose of whichever model node ran last, or nothing, and every workflow
|
|
455
|
+
author had to know to end on a node returning `Event(content=...)` (see
|
|
456
|
+
`guest_check_in.report`). This gives that terminal output event content
|
|
457
|
+
— JSON for a structure, the text itself for a string — IN PLACE, before
|
|
458
|
+
the nested runner stores and yields it, so `AgentTool` reads it as the
|
|
459
|
+
result. Measured on ADK 2.8.0.
|
|
460
|
+
|
|
461
|
+
"TERMINAL" IS ADK'S OWN WORD FOR IT: the node runner lists the workflow's
|
|
462
|
+
own path in that event's `node_info.output_for`, and the workflow then
|
|
463
|
+
emits no duplicate of it. A terminal node that already returned content —
|
|
464
|
+
an `LlmAgent`, or an explicit `Event(content=...)` — is left alone.
|
|
465
|
+
|
|
466
|
+
ONLY WHILE A `WorkflowTool` IS RUNNING THAT WORKFLOW. The same event in a
|
|
467
|
+
workflow launched on its own is not an answer to anybody, and content on
|
|
468
|
+
it would print the output into the chat.
|
|
469
|
+
|
|
470
|
+
Installed by `build_app` on every App, beside `SecurityContextPlugin`, so it
|
|
471
|
+
behaves the same in a pod, under `elan adk web` and in a developer's test.
|
|
309
472
|
"""
|
|
310
|
-
from agentkit_runtime.registry import resolve
|
|
311
473
|
|
|
474
|
+
#: It exists FOR nested runs (ADR-0268) — see `agentkit_plugins.nesting`.
|
|
475
|
+
nested = RUNS_NESTED
|
|
476
|
+
|
|
477
|
+
def __init__(self) -> None:
|
|
478
|
+
super().__init__(name="workflow-result")
|
|
479
|
+
|
|
480
|
+
async def on_event_callback(self, *, invocation_context: Any = None,
|
|
481
|
+
event: Any = None, **_: Any) -> None:
|
|
482
|
+
root = _WORKFLOW_TOOL_ROOT.get()
|
|
483
|
+
if root is None or event is None or getattr(event, "content", None):
|
|
484
|
+
return None
|
|
485
|
+
output = getattr(event, "output", None)
|
|
486
|
+
node_info = getattr(event, "node_info", None)
|
|
487
|
+
answers_for = getattr(node_info, "output_for", None) or []
|
|
488
|
+
if output is None or not any(
|
|
489
|
+
"/" not in path and path.split("@", 1)[0] == root
|
|
490
|
+
for path in answers_for):
|
|
491
|
+
return None
|
|
492
|
+
from google.genai import types # noqa: PLC0415
|
|
493
|
+
|
|
494
|
+
event.content = types.Content(
|
|
495
|
+
role="model", parts=[types.Part(text=_as_result_text(output))])
|
|
496
|
+
return None
|
|
497
|
+
|
|
498
|
+
|
|
499
|
+
def _as_result_text(output: Any) -> str:
|
|
500
|
+
"""A terminal output as the text a calling model reads."""
|
|
501
|
+
if isinstance(output, str):
|
|
502
|
+
return output
|
|
503
|
+
dump = getattr(output, "model_dump", None)
|
|
504
|
+
if callable(dump):
|
|
505
|
+
output = dump(mode="json")
|
|
506
|
+
return json.dumps(output, ensure_ascii=False, default=str)
|
|
507
|
+
|
|
508
|
+
|
|
509
|
+
def _callee(slug: str, settings: Settings, *, kind: str,
|
|
510
|
+
callers: tuple[str, ...]) -> tuple[Target, Any]:
|
|
511
|
+
"""Resolve and build a sibling target for a tool binding (ADR-0269)."""
|
|
512
|
+
from agentkit_runtime.registry import resolve # noqa: PLC0415
|
|
513
|
+
|
|
514
|
+
if slug in callers:
|
|
515
|
+
chain = " -> ".join((*callers, slug))
|
|
516
|
+
raise ValueError(
|
|
517
|
+
f"tool bindings form a cycle: {chain}. A target cannot call itself, "
|
|
518
|
+
"directly or through another, because each one is built inside its "
|
|
519
|
+
"caller.")
|
|
312
520
|
target = resolve(slug, settings)
|
|
313
|
-
if
|
|
314
|
-
|
|
521
|
+
if target.kind != kind:
|
|
522
|
+
other = "agent" if kind == "workflow" else "workflow"
|
|
523
|
+
raise ValueError(
|
|
524
|
+
f"{slug!r} is {'an' if target.kind == 'agent' else 'a'} "
|
|
525
|
+
f"{target.kind}, not {'an' if kind == 'agent' else 'a'} {kind}; "
|
|
526
|
+
f"bind it with `kind: {other}`")
|
|
315
527
|
|
|
316
|
-
ctx = BuildContext(manifest=target.manifest, settings=settings
|
|
528
|
+
ctx = BuildContext(manifest=target.manifest, settings=settings,
|
|
529
|
+
callers=callers)
|
|
317
530
|
_declare_connections(target.manifest)
|
|
318
531
|
root = target.build(ctx)
|
|
319
532
|
# The description is what the calling model reads to decide whether this is
|
|
320
533
|
# the right tool, so it comes from the manifest rather than being restated.
|
|
321
534
|
root.description = target.manifest.description
|
|
535
|
+
return target, root
|
|
536
|
+
|
|
537
|
+
|
|
538
|
+
def workflow_tool(slug: str, settings: Settings, *,
|
|
539
|
+
callers: tuple[str, ...] = ()) -> WorkflowTool:
|
|
540
|
+
"""Resolve another target by slug and hand it back as a callable tool.
|
|
541
|
+
|
|
542
|
+
The callee is built from ITS OWN manifest — its inputs, its node overrides,
|
|
543
|
+
its concurrency, its model — so a workflow behaves identically whether the
|
|
544
|
+
portal launched it or an agent called it. That also means the caller's
|
|
545
|
+
container must contain the callee's code, which it does: one image holds
|
|
546
|
+
every target.
|
|
547
|
+
"""
|
|
548
|
+
target, root = _callee(slug, settings, kind="workflow", callers=callers)
|
|
549
|
+
_prepare_workflow(root, target.manifest)
|
|
550
|
+
prices = prices_of(target.manifest)
|
|
322
551
|
# The same model the graph already validates its launch state against, now
|
|
323
552
|
# doing double duty as the tool's parameter list. One declaration, so the
|
|
324
553
|
# form the model fills in cannot drift from the state the nodes bind.
|
|
@@ -341,25 +570,125 @@ def workflow_tool(slug: str, settings: Settings) -> WorkflowTool:
|
|
|
341
570
|
# the first node parses.
|
|
342
571
|
object.__setattr__(root, "sub_agents", [])
|
|
343
572
|
|
|
344
|
-
#
|
|
573
|
+
# PLUGINS INCLUDED, WHICH IS ADK'S DEFAULT (ADR-0268).
|
|
345
574
|
#
|
|
346
|
-
#
|
|
347
|
-
#
|
|
348
|
-
#
|
|
349
|
-
#
|
|
350
|
-
#
|
|
351
|
-
# settles.
|
|
575
|
+
# This passed `include_plugins=False` because the platform's plugins were
|
|
576
|
+
# not re-entrant: the ledger opened a SECOND hold on the nested
|
|
577
|
+
# `before_run_callback` that nothing settled — measured as four model
|
|
578
|
+
# calls, three holds, two settles. And with no plugins, the workflow's own
|
|
579
|
+
# model calls were charged to nobody and missing from every token count.
|
|
352
580
|
#
|
|
353
|
-
#
|
|
354
|
-
#
|
|
355
|
-
#
|
|
356
|
-
#
|
|
581
|
+
# Each platform plugin now knows a nested run when it sees one
|
|
582
|
+
# (`agentkit_core.context.is_nested`): the hold, the settle and the summary
|
|
583
|
+
# belong to the caller's run and are left alone, while the tally, the
|
|
584
|
+
# solvency gate and the tool meter fold the nested run into it. The caller's
|
|
585
|
+
# `max_llm_calls` still bounds the nested run, because ADK forwards the
|
|
357
586
|
# caller's run_config.
|
|
358
|
-
|
|
359
|
-
#
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
587
|
+
tool = _named(WorkflowTool(agent=root), slug)
|
|
588
|
+
# ITS OWN PRICES, for the nested run's model calls (ADR-0270).
|
|
589
|
+
tool.target_prices = prices
|
|
590
|
+
return tool
|
|
591
|
+
|
|
592
|
+
|
|
593
|
+
def agent_tool(slug: str, settings: Settings, *,
|
|
594
|
+
callers: tuple[str, ...] = ()) -> AgentTool:
|
|
595
|
+
"""Another AGENT in this project, by slug, as a tool (ADR-0269).
|
|
596
|
+
|
|
597
|
+
ADK's own `AgentTool`, unchanged: the sibling's root is an `LlmAgent`, which
|
|
598
|
+
it already knows how to declare — its `input_schema` if it has one, else a
|
|
599
|
+
single `request` string — and its last reply is the result, validated
|
|
600
|
+
against its `output_schema` when it sets one. Plugins included, for the
|
|
601
|
+
same reason as `workflow_tool`, and its own manifest's prices bound for its
|
|
602
|
+
nested run (ADR-0270).
|
|
603
|
+
"""
|
|
604
|
+
target, root = _callee(slug, settings, kind="agent", callers=callers)
|
|
605
|
+
tool = _named(TargetAgentTool(agent=root), slug)
|
|
606
|
+
tool.target_prices = prices_of(target.manifest)
|
|
607
|
+
return tool
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
def _named(tool: AgentTool, slug: str) -> AgentTool:
|
|
611
|
+
"""Name the tool after the callee's SLUG, not its root's Python name.
|
|
612
|
+
|
|
613
|
+
So `actions`, `billing.tool_costs` and the deploy cross-check can key on it
|
|
614
|
+
from the manifest alone (`target_tool_name`), without building anything.
|
|
615
|
+
"""
|
|
616
|
+
tool.name = target_tool_name(slug)
|
|
617
|
+
return tool
|
|
618
|
+
|
|
619
|
+
|
|
620
|
+
def _prepare_workflow(root: Any, manifest: WorkflowManifest) -> None:
|
|
621
|
+
"""The manifest's operational knobs, stitched onto a built graph.
|
|
622
|
+
|
|
623
|
+
SHARED BY `build_app` AND `workflow_tool`, because a workflow called as a
|
|
624
|
+
tool used to skip both — its declared node timeouts and retries and its
|
|
625
|
+
concurrency silently did not apply on that path.
|
|
626
|
+
"""
|
|
627
|
+
_apply_node_overrides(root, manifest)
|
|
628
|
+
if manifest.max_concurrency is not None:
|
|
629
|
+
root.max_concurrency = manifest.max_concurrency
|
|
630
|
+
|
|
631
|
+
|
|
632
|
+
def agent_names(root: Any) -> set[str]:
|
|
633
|
+
"""Every ADK agent's `name` under `root`: sub-agents in any mode, agents
|
|
634
|
+
behind an `AgentTool`, and the agents inside a workflow's nodes — the names
|
|
635
|
+
`Billing.agent_token_costs` can key on (ADR-0270)."""
|
|
636
|
+
from google.adk.agents import BaseAgent # noqa: PLC0415
|
|
637
|
+
|
|
638
|
+
found: set[str] = set()
|
|
639
|
+
seen: set[int] = set()
|
|
640
|
+
|
|
641
|
+
def walk(node: Any) -> None:
|
|
642
|
+
if node is None or id(node) in seen:
|
|
643
|
+
return
|
|
644
|
+
seen.add(id(node))
|
|
645
|
+
if isinstance(node, BaseAgent):
|
|
646
|
+
found.add(node.name)
|
|
647
|
+
for tool in getattr(node, "tools", None) or ():
|
|
648
|
+
walk(getattr(tool, "agent", None))
|
|
649
|
+
for child in getattr(node, "sub_agents", None) or ():
|
|
650
|
+
walk(child)
|
|
651
|
+
graph = getattr(node, "graph", None)
|
|
652
|
+
for child in getattr(graph, "nodes", None) or ():
|
|
653
|
+
walk(child)
|
|
654
|
+
walk(getattr(node, "agent", None))
|
|
655
|
+
|
|
656
|
+
walk(root)
|
|
657
|
+
return found
|
|
658
|
+
|
|
659
|
+
|
|
660
|
+
def unmetered_agent_tools(root: Any) -> list[str]:
|
|
661
|
+
"""Every `AgentTool` under `root` built with `include_plugins=False`.
|
|
662
|
+
|
|
663
|
+
ITS NESTED RUN IS INVISIBLE TO BILLING AND TO OBSERVABILITY: no plugin
|
|
664
|
+
callback fires inside it, so its model calls are charged to nobody and
|
|
665
|
+
missing from every token count (ADR-0268). This platform's docs used to
|
|
666
|
+
recommend exactly that, so it is reported rather than refused — a refusal
|
|
667
|
+
would stop a deployed agent at its next pod start after an upgrade.
|
|
668
|
+
"""
|
|
669
|
+
found: list[str] = []
|
|
670
|
+
seen: set[int] = set()
|
|
671
|
+
|
|
672
|
+
def walk(node: Any) -> None:
|
|
673
|
+
if node is None or id(node) in seen:
|
|
674
|
+
return
|
|
675
|
+
seen.add(id(node))
|
|
676
|
+
if isinstance(node, AgentTool):
|
|
677
|
+
if not node.include_plugins:
|
|
678
|
+
found.append(node.name)
|
|
679
|
+
walk(node.agent)
|
|
680
|
+
return
|
|
681
|
+
for tool in getattr(node, "tools", None) or ():
|
|
682
|
+
walk(tool)
|
|
683
|
+
for child in getattr(node, "sub_agents", None) or ():
|
|
684
|
+
walk(child)
|
|
685
|
+
graph = getattr(node, "graph", None)
|
|
686
|
+
for child in getattr(graph, "nodes", None) or ():
|
|
687
|
+
walk(child)
|
|
688
|
+
walk(getattr(node, "agent", None))
|
|
689
|
+
|
|
690
|
+
walk(root)
|
|
691
|
+
return found
|
|
363
692
|
|
|
364
693
|
|
|
365
694
|
@dataclass(frozen=True)
|
|
@@ -372,26 +701,38 @@ class BuildContext:
|
|
|
372
701
|
|
|
373
702
|
manifest: BaseTargetManifest
|
|
374
703
|
settings: Settings
|
|
704
|
+
callers: tuple[str, ...] = ()
|
|
705
|
+
"""The targets whose tools are being built that led to this one — empty
|
|
706
|
+
for the target a pod runs. Only a cycle check reads it."""
|
|
375
707
|
|
|
376
708
|
@property
|
|
377
709
|
def slug(self) -> str:
|
|
378
710
|
return self.manifest.slug
|
|
379
711
|
|
|
380
712
|
def tools(self) -> list[Any]:
|
|
381
|
-
"""The manifest's tool bindings, resolved to ADK toolsets.
|
|
713
|
+
"""The manifest's tool bindings, resolved to ADK tools and toolsets.
|
|
382
714
|
|
|
383
715
|
A target calls this from build() rather than receiving tools
|
|
384
|
-
pre-attached, so an agent that wants to wrap or reorder them can.
|
|
716
|
+
pre-attached, so an agent that wants to wrap or reorder them can. A
|
|
717
|
+
`workflow` or `agent` binding becomes one tool here (ADR-0269).
|
|
385
718
|
"""
|
|
386
|
-
return build_tools(self.manifest)
|
|
719
|
+
return build_tools(self.manifest, self.settings, callers=self.callers)
|
|
387
720
|
|
|
388
721
|
def workflow_tool(self, slug: str) -> Any:
|
|
389
722
|
"""Another target's graph, as a tool this agent can call.
|
|
390
723
|
|
|
391
724
|
The agent declares WHICH workflow; the workflow keeps declaring its own
|
|
392
|
-
inputs. Neither restates the other.
|
|
725
|
+
inputs. Neither restates the other. Prefer a `kind: workflow` binding
|
|
726
|
+
in `tools`, which the deploy can see and check; this is the same tool,
|
|
727
|
+
for an agent that builds its tool list in code.
|
|
393
728
|
"""
|
|
394
|
-
return workflow_tool(slug, self.settings
|
|
729
|
+
return workflow_tool(slug, self.settings,
|
|
730
|
+
callers=(*self.callers, self.slug))
|
|
731
|
+
|
|
732
|
+
def agent_tool(self, slug: str) -> Any:
|
|
733
|
+
"""Another agent in this project, as a tool this agent can call — the
|
|
734
|
+
code-side twin of a `kind: agent` binding (ADR-0269)."""
|
|
735
|
+
return agent_tool(slug, self.settings, callers=(*self.callers, self.slug))
|
|
395
736
|
|
|
396
737
|
def state_schema(self) -> Any:
|
|
397
738
|
"""The manifest's declared inputs as a Pydantic model, or None.
|
|
@@ -549,9 +890,7 @@ def build_app(target: Target, settings: Settings, plugins: list[Any] | None = No
|
|
|
549
890
|
f"state_schema. Pass state_schema=ctx.state_schema() to Workflow(...), "
|
|
550
891
|
f"or nothing checks that the nodes' parameters match the launch form."
|
|
551
892
|
)
|
|
552
|
-
|
|
553
|
-
if manifest.max_concurrency is not None:
|
|
554
|
-
root.max_concurrency = manifest.max_concurrency
|
|
893
|
+
_prepare_workflow(root, manifest)
|
|
555
894
|
if manifest.resumable:
|
|
556
895
|
# Lets the workflow pause on a long-running tool and resume from the
|
|
557
896
|
# last event, which is what keeps a human-approval step from having
|
|
@@ -568,8 +907,16 @@ def build_app(target: Target, settings: Settings, plugins: list[Any] | None = No
|
|
|
568
907
|
StaticSource,
|
|
569
908
|
)
|
|
570
909
|
|
|
910
|
+
for name in unmetered_agent_tools(root):
|
|
911
|
+
logger.error(
|
|
912
|
+
"%s offers %r as an AgentTool with include_plugins=False. Its "
|
|
913
|
+
"nested run fires no plugin callbacks, so its model calls are "
|
|
914
|
+
"charged to nobody and missing from every token count. Remove "
|
|
915
|
+
"include_plugins=False: the platform's plugins handle a nested "
|
|
916
|
+
"run (ADR-0268).", manifest.slug, name)
|
|
917
|
+
|
|
571
918
|
credentials = SecurityContextPlugin(
|
|
572
|
-
declared=
|
|
919
|
+
declared=declared_credentials(manifest, settings),
|
|
573
920
|
inner=your_credential_service(target),
|
|
574
921
|
source=(StaticSource(_context_of(security_context))
|
|
575
922
|
if security_context is not None else None))
|
|
@@ -577,10 +924,15 @@ def build_app(target: Target, settings: Settings, plugins: list[Any] | None = No
|
|
|
577
924
|
return App(
|
|
578
925
|
name=app_name_of(manifest.slug, settings),
|
|
579
926
|
root_agent=root,
|
|
580
|
-
|
|
927
|
+
# The workflow-result plugin SECOND and ahead of everything that reads
|
|
928
|
+
# an event: the content it gives a terminal output is the tool result,
|
|
929
|
+
# and a plugin after it seeing the event without that content would
|
|
930
|
+
# disagree with what the caller is handed.
|
|
931
|
+
plugins=[credentials, WorkflowResultPlugin(), *(plugins or [])],
|
|
581
932
|
resumability_config=resumability,
|
|
582
933
|
events_compaction_config=_compaction(
|
|
583
934
|
manifest, root, target.module_name.rpartition(".")[0]),
|
|
935
|
+
context_cache_config=_context_cache(manifest),
|
|
584
936
|
)
|
|
585
937
|
|
|
586
938
|
|
|
@@ -593,6 +945,27 @@ def _context_of(value: Any) -> Any:
|
|
|
593
945
|
return value if isinstance(value, SecurityContext) else parse_security_context(value)
|
|
594
946
|
|
|
595
947
|
|
|
948
|
+
def _context_cache(manifest) -> Any:
|
|
949
|
+
"""`MANIFEST.context_cache`, as ADK's `ContextCacheConfig` — or None.
|
|
950
|
+
|
|
951
|
+
The cache is created at the model provider by the same client every model
|
|
952
|
+
call uses, which is the developer's own key (`llm.keys`), so its storage
|
|
953
|
+
and its discounted tokens are billed to them by the provider and nothing
|
|
954
|
+
here meters either (ADR-0272). None is ADK's "no caching", and the
|
|
955
|
+
default: ADK then warns once about an app whose agents can transfer.
|
|
956
|
+
"""
|
|
957
|
+
wanted = getattr(manifest, "context_cache", None)
|
|
958
|
+
if wanted is None:
|
|
959
|
+
return None
|
|
960
|
+
from google.adk.agents.context_cache_config import ( # noqa: PLC0415
|
|
961
|
+
ContextCacheConfig,
|
|
962
|
+
)
|
|
963
|
+
|
|
964
|
+
return ContextCacheConfig(ttl_seconds=wanted.ttl_seconds,
|
|
965
|
+
cache_intervals=wanted.cache_intervals,
|
|
966
|
+
min_tokens=wanted.min_tokens)
|
|
967
|
+
|
|
968
|
+
|
|
596
969
|
def _compaction(manifest, root, package: str = "") -> EventsCompactionConfig | None:
|
|
597
970
|
"""`MANIFEST.compaction`, as ADK's config — or None, which is the default.
|
|
598
971
|
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/connections.py
RENAMED
|
@@ -23,6 +23,7 @@ import asyncio
|
|
|
23
23
|
import json
|
|
24
24
|
import logging
|
|
25
25
|
import os
|
|
26
|
+
import re
|
|
26
27
|
import time
|
|
27
28
|
from typing import Any
|
|
28
29
|
|
|
@@ -133,6 +134,15 @@ class VaultClient:
|
|
|
133
134
|
# --- the provider ------------------------------------------------------------------------
|
|
134
135
|
|
|
135
136
|
|
|
137
|
+
def _scopes(granted: str) -> list[str]:
|
|
138
|
+
"""The scopes a token response granted.
|
|
139
|
+
|
|
140
|
+
RFC 6749 separates them with spaces; GitHub sends commas (`read:user,repo`)
|
|
141
|
+
and would otherwise be stored as one scope nobody asked for.
|
|
142
|
+
"""
|
|
143
|
+
return [scope for scope in re.split(r"[\s,]+", granted) if scope]
|
|
144
|
+
|
|
145
|
+
|
|
136
146
|
class Provider:
|
|
137
147
|
"""One connection's OAuth endpoints, discovered once per pod."""
|
|
138
148
|
|
|
@@ -215,7 +225,7 @@ class Provider:
|
|
|
215
225
|
refresh_token=body.get("refresh_token") or form.get("refresh_token"),
|
|
216
226
|
token_type=body.get("token_type") or "Bearer",
|
|
217
227
|
expires_at=int(time.time()) + int(expires_in) if expires_in else None,
|
|
218
|
-
scopes=(body.get("scope") or " ".join(self.settings.scopes))
|
|
228
|
+
scopes=_scopes(body.get("scope") or " ".join(self.settings.scopes)))
|
|
219
229
|
|
|
220
230
|
async def exchange(self, code: str, verifier: str, redirect_uri: str) -> TokenSet:
|
|
221
231
|
form = {"grant_type": "authorization_code", "code": code,
|
|
@@ -34,8 +34,10 @@ from google.genai import types
|
|
|
34
34
|
from agentkit_runtime.builder import build_app, credential_service_for
|
|
35
35
|
from agentkit_runtime.concurrency import InvocationLimiter
|
|
36
36
|
from agentkit_runtime.config import Settings
|
|
37
|
+
from agentkit_runtime.graph_export import describe as describe_graph
|
|
37
38
|
from agentkit_runtime.plugins import (
|
|
38
39
|
build_plugins,
|
|
40
|
+
warn_about_unmatched_agent_prices,
|
|
39
41
|
warn_about_unmatched_tool_prices,
|
|
40
42
|
)
|
|
41
43
|
from agentkit_runtime.registry import Target, resolve
|
|
@@ -644,11 +646,19 @@ class Engine:
|
|
|
644
646
|
# target's tool prices in before `build()` has run, so a price naming
|
|
645
647
|
# no real tool cannot be checked until here.
|
|
646
648
|
warn_about_unmatched_tool_prices(target, self.app.root_agent)
|
|
649
|
+
warn_about_unmatched_agent_prices(target, self.app.root_agent)
|
|
647
650
|
# THE APPROVAL TOOLS, FOUND ONCE AT POD START (ADR-0144). A resume has
|
|
648
651
|
# to reach the instance whose callback answers it, and a duplicate name
|
|
649
652
|
# makes that unanswerable — so it raises HERE, where it fails readiness,
|
|
650
653
|
# rather than mid-run in front of somebody.
|
|
651
654
|
self._approvals = collect_approval_tools(self.app.root_agent)
|
|
655
|
+
# A WORKFLOW'S TOPOLOGY, SERIALISED ONCE AT POD START (ADR-0264) and
|
|
656
|
+
# carried on every run's `started` event — so the graph a run is drawn
|
|
657
|
+
# against is the one that RAN, not whatever is deployed by the time
|
|
658
|
+
# somebody looks. After `build_app`, so the manifest's per-node
|
|
659
|
+
# timeouts and retries are already stitched on. None for an agent.
|
|
660
|
+
self._graph = (describe_graph(self.app.root_agent)
|
|
661
|
+
if target.kind == "workflow" else None)
|
|
652
662
|
# SHARED WHEN THE CALLER HAS ONE, BECAUSE THE POOL BELONGS TO THIS
|
|
653
663
|
# OBJECT (ADR-0235). `build_fleet` passes a group's single service, so
|
|
654
664
|
# a pod holds one pool however many members it runs — which is the
|
|
@@ -689,7 +699,7 @@ class Engine:
|
|
|
689
699
|
# THE CALLER'S CREDENTIALS FIRST, THEN THE TARGET'S OWN SERVICE.
|
|
690
700
|
# Without one, ADK's `tool_context.load_credential` raises "Credential
|
|
691
701
|
# service is not initialized" for every tool that asks.
|
|
692
|
-
credential_service=credential_service_for(target),
|
|
702
|
+
credential_service=credential_service_for(target, settings),
|
|
693
703
|
# A push message may be the first the container has seen of a
|
|
694
704
|
# session; let ADK create it rather than racing a get/create pair.
|
|
695
705
|
auto_create_session=True,
|
|
@@ -752,8 +762,15 @@ class Engine:
|
|
|
752
762
|
# delivered it here, so anything that fits in the invoke topic
|
|
753
763
|
# fits in the event topic. Model output is published whole for
|
|
754
764
|
# the same reason.
|
|
755
|
-
|
|
756
|
-
|
|
765
|
+
#
|
|
766
|
+
# AND, FOR A WORKFLOW, THE GRAPH (ADR-0264). The payload is a
|
|
767
|
+
# free dict, so this is no envelope field and no hazard for an
|
|
768
|
+
# already-deployed reader; a client that does not know the key
|
|
769
|
+
# ignores it.
|
|
770
|
+
started: dict[str, Any] = {"text": envelope.text()}
|
|
771
|
+
if self._graph is not None:
|
|
772
|
+
started["graph"] = self._graph
|
|
773
|
+
yield self._emit(envelope, seq, "started", started)
|
|
757
774
|
|
|
758
775
|
# This message abandons whatever confirmations the previous turn
|
|
759
776
|
# is still waiting on — ADK will not say so, so the store is
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"""A built workflow's topology, as plain data (ADR-0264).
|
|
2
|
+
|
|
3
|
+
describe(workflow) -> {"version": 1, "nodes": [...], "edges": [...]}
|
|
4
|
+
|
|
5
|
+
THE GRAPH EXISTED ONLY INSIDE THE POD. Its nodes, edges, routes and node types
|
|
6
|
+
are the result of EXECUTING a target's ``build()``, and nothing wrote them down
|
|
7
|
+
— not ``manifests.json``, not the deploy facts, not the envelope, not
|
|
8
|
+
observability. So every view of a run could show only the nodes that had
|
|
9
|
+
already emitted something: never what was still ahead, never which branch a
|
|
10
|
+
routing node skipped, and never whether a node was a model or a function,
|
|
11
|
+
because no event says. That last one could be INFERRED (only an LlmAgent sets
|
|
12
|
+
an event author), and an inference each client spells for itself is the
|
|
13
|
+
ADR-0116 failure waiting to happen.
|
|
14
|
+
|
|
15
|
+
ONE SERIALISER, TWO CALLERS. The engine puts this on every workflow run's
|
|
16
|
+
``started`` payload, so the topology a run is drawn against is the one that
|
|
17
|
+
RAN rather than whatever is deployed now; and the manifest exporter adds it to
|
|
18
|
+
a target's facts, so a workflow can be drawn before it has run at all.
|
|
19
|
+
|
|
20
|
+
VERIFIED AGAINST THE INSTALLED PACKAGE, not the docs (ADK 2.8): an ``LlmAgent``
|
|
21
|
+
placed in ``edges`` is not wrapped — it IS a ``BaseNode`` — so ``isinstance``
|
|
22
|
+
on the node itself is the whole classification. ``START`` is a bare
|
|
23
|
+
``BaseNode`` named ``__START__``, and a ``Workflow`` is a ``BaseNode`` and NOT
|
|
24
|
+
a ``BaseAgent``. ``tests/test_workflow_graph.py`` builds the real
|
|
25
|
+
``event-planner`` and pins each of those, so an upgrade that starts wrapping
|
|
26
|
+
agents fails there rather than silently typing every model node ``other``.
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
from __future__ import annotations
|
|
30
|
+
|
|
31
|
+
from typing import Any
|
|
32
|
+
|
|
33
|
+
#: Bumped when the SHAPE changes, so a reader holding a run recorded by an
|
|
34
|
+
#: older runtime can tell which one it is reading.
|
|
35
|
+
GRAPH_VERSION = 1
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def describe(workflow: Any) -> dict[str, Any]:
|
|
39
|
+
"""The nodes and edges of a built ``google.adk.workflow.Workflow``.
|
|
40
|
+
|
|
41
|
+
ORDER IS ADK'S: ``Graph.nodes`` is derived from the edges in the order they
|
|
42
|
+
were declared, deduplicated by object identity. Nothing downstream depends
|
|
43
|
+
on it — a layout is computed from the edges — but a stable order keeps two
|
|
44
|
+
exports of one graph byte-identical, which is what makes a facts diff read
|
|
45
|
+
as "nothing changed" when nothing did.
|
|
46
|
+
"""
|
|
47
|
+
graph = getattr(workflow, "graph", None)
|
|
48
|
+
nodes = list(getattr(graph, "nodes", None) or [])
|
|
49
|
+
edges = list(getattr(graph, "edges", None) or [])
|
|
50
|
+
return {
|
|
51
|
+
"version": GRAPH_VERSION,
|
|
52
|
+
"nodes": [_node(node) for node in nodes],
|
|
53
|
+
"edges": [
|
|
54
|
+
{
|
|
55
|
+
"from": str(getattr(edge.from_node, "name", "")),
|
|
56
|
+
"to": str(getattr(edge.to_node, "name", "")),
|
|
57
|
+
"route": _route(getattr(edge, "route", None)),
|
|
58
|
+
}
|
|
59
|
+
for edge in edges
|
|
60
|
+
],
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _node(node: Any) -> dict[str, Any]:
|
|
65
|
+
out: dict[str, Any] = {"name": str(getattr(node, "name", "")),
|
|
66
|
+
"type": node_type(node)}
|
|
67
|
+
if out["type"] == "agent":
|
|
68
|
+
model = _model_name(getattr(node, "model", None))
|
|
69
|
+
if model:
|
|
70
|
+
out["model"] = model
|
|
71
|
+
timeout = getattr(node, "timeout", None)
|
|
72
|
+
if isinstance(timeout, (int, float)):
|
|
73
|
+
out["timeout"] = float(timeout)
|
|
74
|
+
retry = getattr(node, "retry_config", None)
|
|
75
|
+
attempts = getattr(retry, "max_attempts", None)
|
|
76
|
+
if isinstance(attempts, int):
|
|
77
|
+
out["max_attempts"] = attempts
|
|
78
|
+
return out
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def node_type(node: Any) -> str:
|
|
82
|
+
"""``start`` / ``workflow`` / ``agent`` / ``function`` / ``join`` /
|
|
83
|
+
``tool`` / ``other``.
|
|
84
|
+
|
|
85
|
+
LAZY IMPORTS, because the exporter imports this module and a target whose
|
|
86
|
+
graph never needs a class should not pay for loading it. ``Workflow`` is
|
|
87
|
+
tested BEFORE ``BaseAgent`` out of habit rather than necessity — on 2.8 it
|
|
88
|
+
is not an agent — so that a version where it becomes one still types a
|
|
89
|
+
nested graph as a graph.
|
|
90
|
+
"""
|
|
91
|
+
from google.adk.agents import BaseAgent
|
|
92
|
+
from google.adk.workflow import FunctionNode, JoinNode, Workflow
|
|
93
|
+
|
|
94
|
+
if getattr(node, "name", None) == "__START__" and type(node).__name__ == "BaseNode":
|
|
95
|
+
return "start"
|
|
96
|
+
if isinstance(node, Workflow):
|
|
97
|
+
return "workflow"
|
|
98
|
+
if isinstance(node, BaseAgent):
|
|
99
|
+
return "agent"
|
|
100
|
+
if isinstance(node, FunctionNode):
|
|
101
|
+
return "function"
|
|
102
|
+
if isinstance(node, JoinNode):
|
|
103
|
+
return "join"
|
|
104
|
+
if type(node).__name__ == "_ToolNode":
|
|
105
|
+
# PRIVATE IN ADK, so matched by name rather than imported: an import
|
|
106
|
+
# of a private module is a crash on the upgrade that renames it, and a
|
|
107
|
+
# name that stops matching only degrades the badge to `other`.
|
|
108
|
+
return "tool"
|
|
109
|
+
return "other"
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def _model_name(model: Any) -> str:
|
|
113
|
+
"""A model string, or the ``model`` a ``BaseLlm`` wraps (``LiteLlm``)."""
|
|
114
|
+
if isinstance(model, str):
|
|
115
|
+
return model
|
|
116
|
+
name = getattr(model, "model", None)
|
|
117
|
+
return name if isinstance(name, str) else ""
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def _route(route: Any) -> str | list[str] | None:
|
|
121
|
+
"""ADK's ``RouteValue`` is a str, int or bool — or a list of them.
|
|
122
|
+
|
|
123
|
+
STRINGIFIED, because JSON keys a route by its text and the console compares
|
|
124
|
+
it with the ``actions.route`` a node emitted, which arrives as JSON too.
|
|
125
|
+
``__DEFAULT__`` is kept as ADK spells it.
|
|
126
|
+
"""
|
|
127
|
+
if route is None:
|
|
128
|
+
return None
|
|
129
|
+
if isinstance(route, list):
|
|
130
|
+
return [str(value) for value in route]
|
|
131
|
+
return str(route)
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/manifest_export.py
RENAMED
|
@@ -50,15 +50,52 @@ def export(targets_root: Path) -> list[dict]:
|
|
|
50
50
|
for slug, target in targets:
|
|
51
51
|
_check_plugins(slug, target)
|
|
52
52
|
_check_credential_service(slug, target)
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
out = []
|
|
54
|
+
for slug, target in targets:
|
|
55
|
+
entry = {
|
|
55
56
|
"slug": slug,
|
|
56
57
|
"kind": target.kind,
|
|
57
58
|
"module": target.module_name,
|
|
58
59
|
**target.manifest.model_dump(mode="json"),
|
|
59
60
|
}
|
|
60
|
-
|
|
61
|
-
|
|
61
|
+
if target.kind == "workflow":
|
|
62
|
+
graph = _graph_of(slug, target, settings)
|
|
63
|
+
if graph is not None:
|
|
64
|
+
entry["graph"] = graph
|
|
65
|
+
out.append(entry)
|
|
66
|
+
return out
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def _graph_of(slug: str, target, settings: Settings) -> dict | None:
|
|
70
|
+
"""A workflow's topology, for the console to draw before it runs (ADR-0264).
|
|
71
|
+
|
|
72
|
+
BEST-EFFORT, AND THAT IS A DECISION RATHER THAN A SHORTCUT. Everything else
|
|
73
|
+
this exporter checks is something a pod would fail on anyway, so failing
|
|
74
|
+
the build earlier is a kindness. Building the graph is NEW work — this
|
|
75
|
+
module never executed `build()` before — and a `build()` that reaches for
|
|
76
|
+
something only a pod has would become a deploy refusal that did not exist
|
|
77
|
+
yesterday. So a failure is reported on stderr, with the developer's own
|
|
78
|
+
error, and the target ships without a drawn overview; every run still
|
|
79
|
+
carries its graph on `started`, from the pod that really built it.
|
|
80
|
+
|
|
81
|
+
The manifest's per-node overrides are applied first, so a timeout or retry
|
|
82
|
+
the manifest declares is on the drawing as it will be on the pod.
|
|
83
|
+
"""
|
|
84
|
+
from agentkit_runtime.builder import ( # noqa: PLC0415
|
|
85
|
+
BuildContext,
|
|
86
|
+
_apply_node_overrides,
|
|
87
|
+
)
|
|
88
|
+
from agentkit_runtime.graph_export import describe # noqa: PLC0415
|
|
89
|
+
|
|
90
|
+
try:
|
|
91
|
+
root = target.build(BuildContext(manifest=target.manifest, settings=settings))
|
|
92
|
+
_apply_node_overrides(root, target.manifest)
|
|
93
|
+
return describe(root)
|
|
94
|
+
except Exception as exc: # noqa: BLE001 - see the docstring
|
|
95
|
+
print(f"warning: {slug}: could not describe the workflow's graph, so "
|
|
96
|
+
f"its overview will not be drawn until a run records one: {exc}",
|
|
97
|
+
file=sys.stderr)
|
|
98
|
+
return None
|
|
62
99
|
|
|
63
100
|
|
|
64
101
|
def _check_plugins(slug: str, target) -> None:
|
|
@@ -82,6 +82,11 @@ def build_plugins(
|
|
|
82
82
|
# expression over the call's own arguments. Priced tools only,
|
|
83
83
|
# so an unpriced one costs the meter a dict lookup.
|
|
84
84
|
tool_costs=target.manifest.billing.micros_per_call(),
|
|
85
|
+
# WHAT EACH AGENT'S TOKENS COST (ADR-0270): this target's own
|
|
86
|
+
# per-agent prices, and every bound target's prices so the hold is
|
|
87
|
+
# priced — and reserved — for what the run can actually be charged.
|
|
88
|
+
agent_rates=target.manifest.billing.micros_per_mtok_by_agent(),
|
|
89
|
+
bound_prices=_bound_prices(target, settings),
|
|
85
90
|
# The MANIFEST's version, not `version_stamp`. A price's author
|
|
86
91
|
# is the manifest that declared it; the build stamp is already on
|
|
87
92
|
# the hold.
|
|
@@ -273,6 +278,11 @@ def warn_about_unmatched_tool_prices(target: Target, root_agent: Any) -> None:
|
|
|
273
278
|
return
|
|
274
279
|
|
|
275
280
|
known, nested = _tool_names(root_agent)
|
|
281
|
+
# A NESTED AGENT'S TOOL IS PRICEABLE HERE NOW (ADR-0268): the platform's
|
|
282
|
+
# plugins run inside a nested run, so the tool meter charges a call to it
|
|
283
|
+
# against this target's hold and at this target's price — the CALLER is
|
|
284
|
+
# the one selling to the end user.
|
|
285
|
+
known |= nested
|
|
276
286
|
bindings = list(getattr(target.manifest, "tools", []))
|
|
277
287
|
for binding in bindings:
|
|
278
288
|
known.update(binding.tool_filter or ())
|
|
@@ -299,20 +309,6 @@ def warn_about_unmatched_tool_prices(target: Target, root_agent: Any) -> None:
|
|
|
299
309
|
target.slug, len(missing), missing, sorted(known) or ["none"],
|
|
300
310
|
)
|
|
301
311
|
|
|
302
|
-
# A PRICE ON A NESTED AGENT'S TOOL IS NOT METERED HERE, and the distinction
|
|
303
|
-
# is worth a line of its own. `ctx.workflow_tool()` passes
|
|
304
|
-
# `include_plugins=False`, so no callback fires inside the nested run — the
|
|
305
|
-
# WORKFLOW TOOL ITSELF is priceable (and pricing it is the only way to
|
|
306
|
-
# charge for a nested graph at all), while the tools it calls are not.
|
|
307
|
-
for name in sorted(priced & nested):
|
|
308
|
-
logger.warning(
|
|
309
|
-
"%s prices %r, which is a tool of a NESTED agent rather than one "
|
|
310
|
-
"of its own. A nested run fires no plugin callbacks, so this will "
|
|
311
|
-
"never be charged — price the nested agent's own tool entry "
|
|
312
|
-
"instead.",
|
|
313
|
-
target.slug, name,
|
|
314
|
-
)
|
|
315
|
-
|
|
316
312
|
for tool, price in target.manifest.billing.micros_per_call().items():
|
|
317
313
|
for path in sorted(price_vars(price)):
|
|
318
314
|
root = path.split(".")[0]
|
|
@@ -328,6 +324,39 @@ def warn_about_unmatched_tool_prices(target: Target, root_agent: Any) -> None:
|
|
|
328
324
|
)
|
|
329
325
|
|
|
330
326
|
|
|
327
|
+
def _bound_prices(target: Target, settings: Settings) -> list[Any]:
|
|
328
|
+
"""Every price a bound target could charge this target's runs at."""
|
|
329
|
+
from agentkit_runtime.builder import bound_targets # noqa: PLC0415
|
|
330
|
+
|
|
331
|
+
prices: list[Any] = []
|
|
332
|
+
for callee in bound_targets(target.manifest, settings):
|
|
333
|
+
billing = callee.manifest.billing
|
|
334
|
+
prices.append(billing.micros_per_mtok())
|
|
335
|
+
prices.extend(billing.micros_per_mtok_by_agent().values())
|
|
336
|
+
return prices
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def warn_about_unmatched_agent_prices(target: Target, root_agent: Any) -> None:
|
|
340
|
+
"""A price on an agent name nothing in this target is called (ADR-0270).
|
|
341
|
+
|
|
342
|
+
A RENAMED SUB-AGENT SILENTLY MOVES BACK TO THE FLAT PRICE, and nothing
|
|
343
|
+
else would say so: the charge is still made, at the wrong rate. A warning
|
|
344
|
+
rather than a refusal for the reason `warn_about_unmatched_tool_prices`
|
|
345
|
+
gives — a name inside a bound target's build is known here, but nothing
|
|
346
|
+
stops a tenant constructing agents lazily inside a tool.
|
|
347
|
+
"""
|
|
348
|
+
from agentkit_runtime.builder import agent_names # noqa: PLC0415
|
|
349
|
+
|
|
350
|
+
priced = set(target.manifest.billing.agent_token_costs)
|
|
351
|
+
missing = sorted(priced - agent_names(root_agent))
|
|
352
|
+
if missing:
|
|
353
|
+
logger.warning(
|
|
354
|
+
"%s prices the agent(s) %s, which nothing it builds is named. A "
|
|
355
|
+
"per-agent price applies only to model calls made by an agent of "
|
|
356
|
+
"that EXACT name, so these calls are charged the flat price "
|
|
357
|
+
"instead. Check `LlmAgent(name=...)`.", target.slug, missing)
|
|
358
|
+
|
|
359
|
+
|
|
331
360
|
def _tool_names(agent: Any) -> tuple[set[str], set[str]]:
|
|
332
361
|
"""This agent's own tool names, and the names one level beneath it.
|
|
333
362
|
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/security.py
RENAMED
|
@@ -75,6 +75,7 @@ from agentkit_core.security_context import (
|
|
|
75
75
|
name_of_key,
|
|
76
76
|
parse_security_context,
|
|
77
77
|
)
|
|
78
|
+
from agentkit_plugins.nesting import RUNS_NESTED
|
|
78
79
|
from google.adk.auth.auth_credential import (
|
|
79
80
|
AuthCredential,
|
|
80
81
|
AuthCredentialTypes,
|
|
@@ -746,6 +747,12 @@ class SecurityContextPlugin(BasePlugin):
|
|
|
746
747
|
is left exactly as it is.
|
|
747
748
|
"""
|
|
748
749
|
|
|
750
|
+
#: Inside a nested run (ADR-0268): it runs there. A nested runner already
|
|
751
|
+
#: carries the caller's `ElanCredentialService`, so `before_run_callback`
|
|
752
|
+
#: is a no-op, and `on_event_callback` scrubbing secrets is wanted on every
|
|
753
|
+
#: event, nested or not.
|
|
754
|
+
nested = RUNS_NESTED
|
|
755
|
+
|
|
749
756
|
def __init__(self, *, declared: Any = None, inner: Any = None,
|
|
750
757
|
source: CredentialSource | None = None) -> None:
|
|
751
758
|
super().__init__(name="security-context")
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/__init__.py
RENAMED
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/concurrency.py
RENAMED
|
File without changes
|
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/consumer.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/pubsub_push.py
RENAMED
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/registry.py
RENAMED
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/schema_export.py
RENAMED
|
File without changes
|
{elan_agentkit_runtime-0.2.4 → elan_agentkit_runtime-0.2.6}/src/agentkit_runtime/tenant_plugins.py
RENAMED
|
File without changes
|