koda-agent-runtime 0.1.0__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.
- koda_agent_runtime-0.1.0/.gitignore +31 -0
- koda_agent_runtime-0.1.0/LICENSE +21 -0
- koda_agent_runtime-0.1.0/PKG-INFO +158 -0
- koda_agent_runtime-0.1.0/README.md +125 -0
- koda_agent_runtime-0.1.0/pyproject.toml +76 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/__init__.py +76 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/app.py +150 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/config.py +139 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/context.py +43 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/headers.py +42 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/middleware.py +51 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/registry.py +185 -0
- koda_agent_runtime-0.1.0/src/koda_agent_runtime/tools.py +154 -0
- koda_agent_runtime-0.1.0/tests/__init__.py +0 -0
- koda_agent_runtime-0.1.0/tests/test_config.py +97 -0
- koda_agent_runtime-0.1.0/tests/test_context.py +36 -0
- koda_agent_runtime-0.1.0/tests/test_headers.py +54 -0
- koda_agent_runtime-0.1.0/uv.lock +1858 -0
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*.so
|
|
5
|
+
*.egg-info/
|
|
6
|
+
.eggs/
|
|
7
|
+
.pytest_cache/
|
|
8
|
+
.mypy_cache/
|
|
9
|
+
.ruff_cache/
|
|
10
|
+
.tox/
|
|
11
|
+
.coverage
|
|
12
|
+
htmlcov/
|
|
13
|
+
|
|
14
|
+
# Build artifacts
|
|
15
|
+
build/
|
|
16
|
+
dist/
|
|
17
|
+
*.whl
|
|
18
|
+
*.tar.gz
|
|
19
|
+
|
|
20
|
+
# Virtual envs
|
|
21
|
+
.venv/
|
|
22
|
+
venv/
|
|
23
|
+
env/
|
|
24
|
+
|
|
25
|
+
# Editors / OS
|
|
26
|
+
.DS_Store
|
|
27
|
+
.idea/
|
|
28
|
+
.vscode/
|
|
29
|
+
*.swp
|
|
30
|
+
|
|
31
|
+
# uv.lock is tracked (reproducibility). Same convention as koda-mcp-access.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kushki
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: koda-agent-runtime
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Reusable runtime, config loader and bootstrap for KODA-ecosystem A2A agents on Amazon Bedrock AgentCore.
|
|
5
|
+
Project-URL: Homepage, https://bitbucket.org/kushki/koda-agent-runtime
|
|
6
|
+
Project-URL: Repository, https://bitbucket.org/kushki/koda-agent-runtime
|
|
7
|
+
Author: Kushki
|
|
8
|
+
License-Expression: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: a2a,agent,agentcore,bedrock,koda,strands
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Python: >=3.11
|
|
21
|
+
Requires-Dist: fastapi>=0.110.0
|
|
22
|
+
Requires-Dist: pyyaml>=6.0
|
|
23
|
+
Provides-Extra: bootstrap
|
|
24
|
+
Requires-Dist: bedrock-agentcore>=0.1.0; extra == 'bootstrap'
|
|
25
|
+
Requires-Dist: boto3>=1.35.0; extra == 'bootstrap'
|
|
26
|
+
Requires-Dist: strands-agents[a2a]>=0.1.0; extra == 'bootstrap'
|
|
27
|
+
Requires-Dist: uvicorn>=0.30.0; extra == 'bootstrap'
|
|
28
|
+
Provides-Extra: cdk
|
|
29
|
+
Requires-Dist: aws-cdk-aws-bedrock-agentcore-alpha; extra == 'cdk'
|
|
30
|
+
Requires-Dist: aws-cdk-lib>=2.150.0; extra == 'cdk'
|
|
31
|
+
Requires-Dist: constructs>=10.0.0; extra == 'cdk'
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# koda-agent-runtime
|
|
35
|
+
|
|
36
|
+
Runtime compartido para agentes Koda A2A sobre Amazon Bedrock AgentCore.
|
|
37
|
+
Extrae en un solo paquete versionado las piezas que cada `koda-agent-*`
|
|
38
|
+
repite: constantes de custom headers, middleware FastAPI, cliente HTTP
|
|
39
|
+
hacia el registry, decoradores de tools, loader del `agent.yaml`, y un
|
|
40
|
+
bootstrap `build_agent_app(cfg)` que ensambla Strands + A2A + FastAPI
|
|
41
|
+
en una llamada.
|
|
42
|
+
|
|
43
|
+
Ver `KODA_AGENT_RUNTIME_ARCHITECTURE.md` en el monorepo `koda-platform`
|
|
44
|
+
para el diseño completo, precedente (`koda-mcp-access`), roadmap y
|
|
45
|
+
compatibilidad.
|
|
46
|
+
|
|
47
|
+
## Instalación
|
|
48
|
+
|
|
49
|
+
Elige el `extra` según lo que consuma el agente:
|
|
50
|
+
|
|
51
|
+
```toml
|
|
52
|
+
# El mínimo — headers, middleware, registry client, config loader.
|
|
53
|
+
"koda-agent-runtime>=0.1.0a0"
|
|
54
|
+
|
|
55
|
+
# El agente típico — ademas Strands + A2A + Bedrock para build_agent_app.
|
|
56
|
+
"koda-agent-runtime[bootstrap]>=0.1.0a0"
|
|
57
|
+
|
|
58
|
+
# El stack CDK del agente — Construct KodaAgentRuntime.
|
|
59
|
+
"koda-agent-runtime[cdk]>=0.1.0a0"
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Uso — un agente en 10 líneas
|
|
63
|
+
|
|
64
|
+
`src/agent.py`:
|
|
65
|
+
|
|
66
|
+
```python
|
|
67
|
+
from pathlib import Path
|
|
68
|
+
import uvicorn
|
|
69
|
+
from koda_agent_runtime.config import load_agent_config
|
|
70
|
+
from koda_agent_runtime.app import build_agent_app
|
|
71
|
+
|
|
72
|
+
_BASE = Path(__file__).resolve().parent.parent
|
|
73
|
+
app = build_agent_app(load_agent_config(_BASE / "agent.yaml"), base_dir=_BASE)
|
|
74
|
+
|
|
75
|
+
if __name__ == "__main__":
|
|
76
|
+
uvicorn.run(app, host="0.0.0.0", port=9000)
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
`agent.yaml`:
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
name: koda-agent-example
|
|
83
|
+
version: 0.1.0
|
|
84
|
+
description: |
|
|
85
|
+
Un agente de ejemplo.
|
|
86
|
+
|
|
87
|
+
model:
|
|
88
|
+
provider: bedrock
|
|
89
|
+
model_id: us.amazon.nova-lite-v1:0
|
|
90
|
+
temperature: 0.3
|
|
91
|
+
max_tokens: 4000
|
|
92
|
+
|
|
93
|
+
tools:
|
|
94
|
+
- discover_skills
|
|
95
|
+
- fetch_registry_skill
|
|
96
|
+
- invoke_agent
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
## Módulos
|
|
100
|
+
|
|
101
|
+
| Módulo | Responsabilidad |
|
|
102
|
+
|---|---|
|
|
103
|
+
| `koda_agent_runtime.headers` | Constantes `KODA_*_HEADER` + `ALLOWLISTED_HEADERS` (para `agentcore configure --request-header-allowlist`). |
|
|
104
|
+
| `koda_agent_runtime.context` | Module-level `_state` con `bearer` y `request_id`; `set_context`, `get_bearer`, `get_request_id`. |
|
|
105
|
+
| `koda_agent_runtime.middleware` | `koda_headers_middleware(app)` — captura los headers Koda-* que koda-proxy inyecta al invocar el runtime. Salta `/ping` para no borrar el state con health probes. |
|
|
106
|
+
| `koda_agent_runtime.registry` | `discover_agents`, `discover_skills`, `fetch_skill_bundle`, `invoke_peer` — hablan con el registry usando el bearer del state. |
|
|
107
|
+
| `koda_agent_runtime.tools` | Decoradores `@strands.tools.tool` sobre los helpers de `registry`. `build_tools(cfg)` filtra por lo declarado en `agent.yaml.tools`. |
|
|
108
|
+
| `koda_agent_runtime.config` | `load_agent_config(path)` → dataclass tipado `AgentConfig`. |
|
|
109
|
+
| `koda_agent_runtime.app` | `build_agent_app(cfg, base_dir)` → `FastAPI` con Strands `Agent` + `A2AServer` + middleware montados. Requiere `[bootstrap]` extra. |
|
|
110
|
+
|
|
111
|
+
## Contrato de headers Koda-*
|
|
112
|
+
|
|
113
|
+
koda-proxy (broker del registry) inyecta 8 custom headers al invocar
|
|
114
|
+
tu runtime. AgentCore solo forwardea headers con prefix
|
|
115
|
+
`X-Amzn-Bedrock-AgentCore-Runtime-Custom-`.
|
|
116
|
+
|
|
117
|
+
| Header | Contenido | Estable en cadenas A→B→C |
|
|
118
|
+
|---|---|---|
|
|
119
|
+
| `Koda-Authorization` | Bearer JWT vigente (Okta o self-signed 8h). | No — se refresca cuando expira. |
|
|
120
|
+
| `Koda-Sub` | Usuario humano original. | Sí. |
|
|
121
|
+
| `Koda-Email` | Email del usuario. | Sí. |
|
|
122
|
+
| `Koda-Roles` | Groups Okta del usuario. | Sí. |
|
|
123
|
+
| `Koda-Chain-Depth` | Hops desde el usuario. | +1 por hop. |
|
|
124
|
+
| `Koda-Request-Id` | uuid para trace end-to-end. | Sí. |
|
|
125
|
+
| `Koda-Agent-Path` | Path del agente que recibe. | N/A. |
|
|
126
|
+
| `Koda-Caller-Type` | `user` \| `agent`. | Depende del hop. |
|
|
127
|
+
|
|
128
|
+
Todos los strings viven en `koda_agent_runtime.headers` como constantes.
|
|
129
|
+
Nunca los repitas en tu código.
|
|
130
|
+
|
|
131
|
+
## Anti-patrones
|
|
132
|
+
|
|
133
|
+
- **No** uses `contextvars.ContextVar` para propagar el bearer entre
|
|
134
|
+
middleware y tools: Strands corre tools en threads distintos al
|
|
135
|
+
request handler; el ContextVar aparece vacío. Usa `set_context()`.
|
|
136
|
+
- **No** firmes SigV4 desde el agente para invocar peers. Delega via
|
|
137
|
+
`invoke_peer(<path>, <msg>)` — el registry firma por ti.
|
|
138
|
+
- **No** llames `set_context()` en el middleware si no hay bearer. Los
|
|
139
|
+
`/ping` de AgentCore te borrarían el state que otra request iba a
|
|
140
|
+
usar.
|
|
141
|
+
|
|
142
|
+
## Desarrollo
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
uv sync --dev
|
|
146
|
+
uv run pytest
|
|
147
|
+
uv run ruff check src/
|
|
148
|
+
uv build
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Release: bump `pyproject.toml`, tag `vX.Y.Z`, push tag.
|
|
152
|
+
|
|
153
|
+
## Versionado
|
|
154
|
+
|
|
155
|
+
- **v0.x** — alpha, breaking changes tolerados. Todos los agentes en
|
|
156
|
+
migración inicial.
|
|
157
|
+
- **v1.0.0** — cuando la API sea estable y >=3 agentes la consuman en
|
|
158
|
+
producción. A partir de acá, SemVer estricto.
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# koda-agent-runtime
|
|
2
|
+
|
|
3
|
+
Runtime compartido para agentes Koda A2A sobre Amazon Bedrock AgentCore.
|
|
4
|
+
Extrae en un solo paquete versionado las piezas que cada `koda-agent-*`
|
|
5
|
+
repite: constantes de custom headers, middleware FastAPI, cliente HTTP
|
|
6
|
+
hacia el registry, decoradores de tools, loader del `agent.yaml`, y un
|
|
7
|
+
bootstrap `build_agent_app(cfg)` que ensambla Strands + A2A + FastAPI
|
|
8
|
+
en una llamada.
|
|
9
|
+
|
|
10
|
+
Ver `KODA_AGENT_RUNTIME_ARCHITECTURE.md` en el monorepo `koda-platform`
|
|
11
|
+
para el diseño completo, precedente (`koda-mcp-access`), roadmap y
|
|
12
|
+
compatibilidad.
|
|
13
|
+
|
|
14
|
+
## Instalación
|
|
15
|
+
|
|
16
|
+
Elige el `extra` según lo que consuma el agente:
|
|
17
|
+
|
|
18
|
+
```toml
|
|
19
|
+
# El mínimo — headers, middleware, registry client, config loader.
|
|
20
|
+
"koda-agent-runtime>=0.1.0a0"
|
|
21
|
+
|
|
22
|
+
# El agente típico — ademas Strands + A2A + Bedrock para build_agent_app.
|
|
23
|
+
"koda-agent-runtime[bootstrap]>=0.1.0a0"
|
|
24
|
+
|
|
25
|
+
# El stack CDK del agente — Construct KodaAgentRuntime.
|
|
26
|
+
"koda-agent-runtime[cdk]>=0.1.0a0"
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Uso — un agente en 10 líneas
|
|
30
|
+
|
|
31
|
+
`src/agent.py`:
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from pathlib import Path
|
|
35
|
+
import uvicorn
|
|
36
|
+
from koda_agent_runtime.config import load_agent_config
|
|
37
|
+
from koda_agent_runtime.app import build_agent_app
|
|
38
|
+
|
|
39
|
+
_BASE = Path(__file__).resolve().parent.parent
|
|
40
|
+
app = build_agent_app(load_agent_config(_BASE / "agent.yaml"), base_dir=_BASE)
|
|
41
|
+
|
|
42
|
+
if __name__ == "__main__":
|
|
43
|
+
uvicorn.run(app, host="0.0.0.0", port=9000)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
`agent.yaml`:
|
|
47
|
+
|
|
48
|
+
```yaml
|
|
49
|
+
name: koda-agent-example
|
|
50
|
+
version: 0.1.0
|
|
51
|
+
description: |
|
|
52
|
+
Un agente de ejemplo.
|
|
53
|
+
|
|
54
|
+
model:
|
|
55
|
+
provider: bedrock
|
|
56
|
+
model_id: us.amazon.nova-lite-v1:0
|
|
57
|
+
temperature: 0.3
|
|
58
|
+
max_tokens: 4000
|
|
59
|
+
|
|
60
|
+
tools:
|
|
61
|
+
- discover_skills
|
|
62
|
+
- fetch_registry_skill
|
|
63
|
+
- invoke_agent
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Módulos
|
|
67
|
+
|
|
68
|
+
| Módulo | Responsabilidad |
|
|
69
|
+
|---|---|
|
|
70
|
+
| `koda_agent_runtime.headers` | Constantes `KODA_*_HEADER` + `ALLOWLISTED_HEADERS` (para `agentcore configure --request-header-allowlist`). |
|
|
71
|
+
| `koda_agent_runtime.context` | Module-level `_state` con `bearer` y `request_id`; `set_context`, `get_bearer`, `get_request_id`. |
|
|
72
|
+
| `koda_agent_runtime.middleware` | `koda_headers_middleware(app)` — captura los headers Koda-* que koda-proxy inyecta al invocar el runtime. Salta `/ping` para no borrar el state con health probes. |
|
|
73
|
+
| `koda_agent_runtime.registry` | `discover_agents`, `discover_skills`, `fetch_skill_bundle`, `invoke_peer` — hablan con el registry usando el bearer del state. |
|
|
74
|
+
| `koda_agent_runtime.tools` | Decoradores `@strands.tools.tool` sobre los helpers de `registry`. `build_tools(cfg)` filtra por lo declarado en `agent.yaml.tools`. |
|
|
75
|
+
| `koda_agent_runtime.config` | `load_agent_config(path)` → dataclass tipado `AgentConfig`. |
|
|
76
|
+
| `koda_agent_runtime.app` | `build_agent_app(cfg, base_dir)` → `FastAPI` con Strands `Agent` + `A2AServer` + middleware montados. Requiere `[bootstrap]` extra. |
|
|
77
|
+
|
|
78
|
+
## Contrato de headers Koda-*
|
|
79
|
+
|
|
80
|
+
koda-proxy (broker del registry) inyecta 8 custom headers al invocar
|
|
81
|
+
tu runtime. AgentCore solo forwardea headers con prefix
|
|
82
|
+
`X-Amzn-Bedrock-AgentCore-Runtime-Custom-`.
|
|
83
|
+
|
|
84
|
+
| Header | Contenido | Estable en cadenas A→B→C |
|
|
85
|
+
|---|---|---|
|
|
86
|
+
| `Koda-Authorization` | Bearer JWT vigente (Okta o self-signed 8h). | No — se refresca cuando expira. |
|
|
87
|
+
| `Koda-Sub` | Usuario humano original. | Sí. |
|
|
88
|
+
| `Koda-Email` | Email del usuario. | Sí. |
|
|
89
|
+
| `Koda-Roles` | Groups Okta del usuario. | Sí. |
|
|
90
|
+
| `Koda-Chain-Depth` | Hops desde el usuario. | +1 por hop. |
|
|
91
|
+
| `Koda-Request-Id` | uuid para trace end-to-end. | Sí. |
|
|
92
|
+
| `Koda-Agent-Path` | Path del agente que recibe. | N/A. |
|
|
93
|
+
| `Koda-Caller-Type` | `user` \| `agent`. | Depende del hop. |
|
|
94
|
+
|
|
95
|
+
Todos los strings viven en `koda_agent_runtime.headers` como constantes.
|
|
96
|
+
Nunca los repitas en tu código.
|
|
97
|
+
|
|
98
|
+
## Anti-patrones
|
|
99
|
+
|
|
100
|
+
- **No** uses `contextvars.ContextVar` para propagar el bearer entre
|
|
101
|
+
middleware y tools: Strands corre tools en threads distintos al
|
|
102
|
+
request handler; el ContextVar aparece vacío. Usa `set_context()`.
|
|
103
|
+
- **No** firmes SigV4 desde el agente para invocar peers. Delega via
|
|
104
|
+
`invoke_peer(<path>, <msg>)` — el registry firma por ti.
|
|
105
|
+
- **No** llames `set_context()` en el middleware si no hay bearer. Los
|
|
106
|
+
`/ping` de AgentCore te borrarían el state que otra request iba a
|
|
107
|
+
usar.
|
|
108
|
+
|
|
109
|
+
## Desarrollo
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
uv sync --dev
|
|
113
|
+
uv run pytest
|
|
114
|
+
uv run ruff check src/
|
|
115
|
+
uv build
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
Release: bump `pyproject.toml`, tag `vX.Y.Z`, push tag.
|
|
119
|
+
|
|
120
|
+
## Versionado
|
|
121
|
+
|
|
122
|
+
- **v0.x** — alpha, breaking changes tolerados. Todos los agentes en
|
|
123
|
+
migración inicial.
|
|
124
|
+
- **v1.0.0** — cuando la API sea estable y >=3 agentes la consuman en
|
|
125
|
+
producción. A partir de acá, SemVer estricto.
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "koda-agent-runtime"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Reusable runtime, config loader and bootstrap for KODA-ecosystem A2A agents on Amazon Bedrock AgentCore."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.11"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
authors = [{ name = "Kushki" }]
|
|
10
|
+
keywords = ["a2a", "agentcore", "bedrock", "strands", "koda", "agent"]
|
|
11
|
+
classifiers = [
|
|
12
|
+
"Development Status :: 4 - Beta",
|
|
13
|
+
"Intended Audience :: Developers",
|
|
14
|
+
"Operating System :: OS Independent",
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Programming Language :: Python :: 3.11",
|
|
17
|
+
"Programming Language :: Python :: 3.12",
|
|
18
|
+
"Programming Language :: Python :: 3.13",
|
|
19
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
20
|
+
"Typing :: Typed",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
# Core deps — lo mínimo para que `runtime` y `config` funcionen (importar
|
|
24
|
+
# headers, middleware, config loader, registry client, tools). Nada de
|
|
25
|
+
# Strands/Bedrock/CDK: esos van en extras.
|
|
26
|
+
dependencies = [
|
|
27
|
+
"fastapi>=0.110.0",
|
|
28
|
+
"pyyaml>=6.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
# `bootstrap`: para consumir `build_agent_app`. Requiere Strands + Bedrock
|
|
33
|
+
# runtime + a2a-sdk (los tipos `AgentSkill`). Es lo que la mayoría de los
|
|
34
|
+
# agentes va a instalar en producción.
|
|
35
|
+
bootstrap = [
|
|
36
|
+
"strands-agents[a2a]>=0.1.0",
|
|
37
|
+
"bedrock-agentcore>=0.1.0",
|
|
38
|
+
"boto3>=1.35.0",
|
|
39
|
+
"uvicorn>=0.30.0",
|
|
40
|
+
]
|
|
41
|
+
|
|
42
|
+
# `cdk`: para consumir el Construct `KodaAgentRuntime`. Solo relevante en
|
|
43
|
+
# el CDK del agente, no en el runtime.
|
|
44
|
+
cdk = [
|
|
45
|
+
"aws-cdk-lib>=2.150.0",
|
|
46
|
+
"aws-cdk.aws-bedrock-agentcore-alpha",
|
|
47
|
+
"constructs>=10.0.0",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
[project.urls]
|
|
51
|
+
Homepage = "https://bitbucket.org/kushki/koda-agent-runtime"
|
|
52
|
+
Repository = "https://bitbucket.org/kushki/koda-agent-runtime"
|
|
53
|
+
|
|
54
|
+
[dependency-groups]
|
|
55
|
+
dev = [
|
|
56
|
+
"pytest>=8.0.0",
|
|
57
|
+
"pytest-asyncio>=0.24.0",
|
|
58
|
+
"ruff>=0.6.0",
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[build-system]
|
|
62
|
+
requires = ["hatchling"]
|
|
63
|
+
build-backend = "hatchling.build"
|
|
64
|
+
|
|
65
|
+
[tool.hatch.build.targets.wheel]
|
|
66
|
+
packages = ["src/koda_agent_runtime"]
|
|
67
|
+
|
|
68
|
+
[tool.ruff]
|
|
69
|
+
line-length = 100
|
|
70
|
+
target-version = "py311"
|
|
71
|
+
|
|
72
|
+
[tool.ruff.lint]
|
|
73
|
+
select = ["E", "F", "W", "I", "UP", "B"]
|
|
74
|
+
|
|
75
|
+
[tool.pytest.ini_options]
|
|
76
|
+
asyncio_mode = "auto"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Runtime común para agentes Koda expuestos por A2A sobre Amazon Bedrock AgentCore.
|
|
2
|
+
|
|
3
|
+
Cinco piezas reutilizables, todas activables a la carta desde el
|
|
4
|
+
``pyproject.toml`` del agente vía ``extras``:
|
|
5
|
+
|
|
6
|
+
* ``headers`` — constantes de custom headers ``Koda-*`` (fuente única).
|
|
7
|
+
* ``context`` — module-level state donde el middleware guarda bearer+request_id.
|
|
8
|
+
* ``middleware`` — factory FastAPI que captura los headers y salta ``/ping``.
|
|
9
|
+
* ``registry`` — helpers HTTP para descubrir agentes/skills, fetch bundle e
|
|
10
|
+
invocar peers vía el registry (el broker firma SigV4).
|
|
11
|
+
* ``config`` — loader/validador de ``agent.yaml``.
|
|
12
|
+
* ``tools`` — decoradores ``@strands.tools.tool`` que envuelven los helpers.
|
|
13
|
+
* ``app`` — ``build_agent_app(cfg)`` que ensambla el ASGI completo (Strands+A2A).
|
|
14
|
+
|
|
15
|
+
Un agente minimalista consume el ``runtime`` extra y llama a las piezas
|
|
16
|
+
individuales; un agente completo consume el ``bootstrap`` extra y su
|
|
17
|
+
``src/agent.py`` baja a ~10 líneas.
|
|
18
|
+
|
|
19
|
+
Ver ``KODA_AGENT_RUNTIME_ARCHITECTURE.md`` en el monorepo koda-platform
|
|
20
|
+
para el diseño completo y el plan de release.
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
from .config import AgentConfig, load_a2a_skills_from_card, load_agent_config
|
|
24
|
+
from .context import get_bearer, get_request_id, set_context
|
|
25
|
+
from .headers import (
|
|
26
|
+
AGENTCORE_HEADER_PREFIX,
|
|
27
|
+
ALLOWLISTED_HEADERS,
|
|
28
|
+
KODA_AGENT_PATH_HEADER,
|
|
29
|
+
KODA_AUTHZ_HEADER,
|
|
30
|
+
KODA_CALLER_TYPE_HEADER,
|
|
31
|
+
KODA_CHAIN_DEPTH_HEADER,
|
|
32
|
+
KODA_EMAIL_HEADER,
|
|
33
|
+
KODA_REQUEST_ID_HEADER,
|
|
34
|
+
KODA_ROLES_HEADER,
|
|
35
|
+
KODA_SUB_HEADER,
|
|
36
|
+
)
|
|
37
|
+
from .middleware import koda_headers_middleware
|
|
38
|
+
from .registry import (
|
|
39
|
+
RegistryError,
|
|
40
|
+
discover_agents,
|
|
41
|
+
discover_skills,
|
|
42
|
+
fetch_skill_bundle,
|
|
43
|
+
invoke_peer,
|
|
44
|
+
)
|
|
45
|
+
from .tools import build_tools
|
|
46
|
+
|
|
47
|
+
__all__ = [
|
|
48
|
+
"AGENTCORE_HEADER_PREFIX",
|
|
49
|
+
"ALLOWLISTED_HEADERS",
|
|
50
|
+
"AgentConfig",
|
|
51
|
+
"KODA_AGENT_PATH_HEADER",
|
|
52
|
+
"KODA_AUTHZ_HEADER",
|
|
53
|
+
"KODA_CALLER_TYPE_HEADER",
|
|
54
|
+
"KODA_CHAIN_DEPTH_HEADER",
|
|
55
|
+
"KODA_EMAIL_HEADER",
|
|
56
|
+
"KODA_REQUEST_ID_HEADER",
|
|
57
|
+
"KODA_ROLES_HEADER",
|
|
58
|
+
"KODA_SUB_HEADER",
|
|
59
|
+
"RegistryError",
|
|
60
|
+
"build_tools",
|
|
61
|
+
"discover_agents",
|
|
62
|
+
"discover_skills",
|
|
63
|
+
"fetch_skill_bundle",
|
|
64
|
+
"get_bearer",
|
|
65
|
+
"get_request_id",
|
|
66
|
+
"invoke_peer",
|
|
67
|
+
"koda_headers_middleware",
|
|
68
|
+
"load_a2a_skills_from_card",
|
|
69
|
+
"load_agent_config",
|
|
70
|
+
"set_context",
|
|
71
|
+
]
|
|
72
|
+
|
|
73
|
+
# `build_agent_app` NO se exporta desde el top-level porque su import
|
|
74
|
+
# desencadena `strands` + `bedrock` (dependencias pesadas del extra
|
|
75
|
+
# `bootstrap`, no del core). Los consumidores lo importan explícito:
|
|
76
|
+
# from koda_agent_runtime.app import build_agent_app
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"""Bootstrap: construye una app FastAPI + Strands A2A a partir de ``AgentConfig``.
|
|
2
|
+
|
|
3
|
+
Reduce el `src/agent.py` típico de un agente Koda a ~10 líneas. Ver
|
|
4
|
+
``AGENT_SPEC.md`` en koda-platform y §4.3 de
|
|
5
|
+
``KODA_AGENT_RUNTIME_ARCHITECTURE.md`` para la motivación.
|
|
6
|
+
|
|
7
|
+
Ejemplo:
|
|
8
|
+
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
from koda_agent_runtime.config import load_agent_config
|
|
11
|
+
from koda_agent_runtime.app import build_agent_app
|
|
12
|
+
|
|
13
|
+
_BASE = Path(__file__).resolve().parent.parent
|
|
14
|
+
app = build_agent_app(load_agent_config(_BASE / "agent.yaml"), base_dir=_BASE)
|
|
15
|
+
|
|
16
|
+
Agentes que quieran inyectar tools locales pueden pasarlas con
|
|
17
|
+
``extra_tools=[...]``; agentes con requerimientos más raros pueden
|
|
18
|
+
saltarse este helper y usar directo ``koda_agent_runtime.middleware`` y
|
|
19
|
+
``koda_agent_runtime.tools``.
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
from __future__ import annotations
|
|
23
|
+
|
|
24
|
+
import logging
|
|
25
|
+
import os
|
|
26
|
+
from pathlib import Path
|
|
27
|
+
from typing import Any
|
|
28
|
+
|
|
29
|
+
from fastapi import FastAPI
|
|
30
|
+
|
|
31
|
+
from .config import AgentConfig, load_a2a_skills_from_card
|
|
32
|
+
from .middleware import koda_headers_middleware
|
|
33
|
+
from .tools import build_tools
|
|
34
|
+
|
|
35
|
+
logger = logging.getLogger(__name__)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def build_agent_app(
|
|
39
|
+
cfg: AgentConfig,
|
|
40
|
+
*,
|
|
41
|
+
base_dir: Path,
|
|
42
|
+
extra_tools: list[Any] | None = None,
|
|
43
|
+
) -> FastAPI:
|
|
44
|
+
"""Ensambla un ASGI app completo para un agente Koda.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
cfg: Config parseada del ``agent.yaml``.
|
|
48
|
+
base_dir: Directorio raíz del agente (donde viven ``prompts/`` y
|
|
49
|
+
``a2a/``). Normalmente ``Path(__file__).resolve().parent.parent``
|
|
50
|
+
desde ``src/agent.py``.
|
|
51
|
+
extra_tools: Herramientas locales del agente que no están en el
|
|
52
|
+
catálogo compartido. Se anexan a las declaradas en
|
|
53
|
+
``agent.yaml.tools``.
|
|
54
|
+
"""
|
|
55
|
+
# Imports lazy: Strands/Bedrock son pesados y no todos los consumidores
|
|
56
|
+
# del paquete necesitan el bootstrap (algunos usan solo runtime/config).
|
|
57
|
+
from strands import Agent
|
|
58
|
+
from strands.models import BedrockModel
|
|
59
|
+
from strands.multiagent.a2a import A2AServer
|
|
60
|
+
|
|
61
|
+
prompt_path = base_dir / "prompts" / "system.md"
|
|
62
|
+
card_path = base_dir / "a2a" / "agent-card.json"
|
|
63
|
+
for p in (prompt_path, card_path):
|
|
64
|
+
if not p.exists():
|
|
65
|
+
raise FileNotFoundError(f"agent bootstrap missing required file: {p}")
|
|
66
|
+
|
|
67
|
+
prompt = prompt_path.read_text(encoding="utf-8")
|
|
68
|
+
|
|
69
|
+
# Origen de las skills (flag KODA_SKILLS_SOURCE, ver load_skills_for_agent):
|
|
70
|
+
# - "offline" (default, dev): lee skills/<name>/SKILL.md del disco y las
|
|
71
|
+
# inyecta al system prompt en arranque. No depende del registry.
|
|
72
|
+
# - "registry": NO inyecta en arranque; el agente resuelve skills en runtime
|
|
73
|
+
# con la tool `fetch_registry_skill` (necesita el JWT por-request).
|
|
74
|
+
skills_text = load_skills_for_agent(base_dir)
|
|
75
|
+
if skills_text:
|
|
76
|
+
prompt = f"{prompt}\n\n{skills_text}"
|
|
77
|
+
logger.info("skills offline cargadas en el prompt (%d chars)", len(skills_text))
|
|
78
|
+
|
|
79
|
+
tools = build_tools(cfg) + list(extra_tools or [])
|
|
80
|
+
|
|
81
|
+
agent = Agent(
|
|
82
|
+
model=BedrockModel(**cfg.model_kwargs()),
|
|
83
|
+
system_prompt=prompt,
|
|
84
|
+
tools=tools,
|
|
85
|
+
name=cfg.name,
|
|
86
|
+
description=cfg.description,
|
|
87
|
+
)
|
|
88
|
+
|
|
89
|
+
a2a_server = A2AServer(
|
|
90
|
+
agent=agent,
|
|
91
|
+
http_url=cfg.runtime_url(),
|
|
92
|
+
serve_at_root=True,
|
|
93
|
+
version=cfg.version,
|
|
94
|
+
skills=load_a2a_skills_from_card(card_path),
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
app = FastAPI()
|
|
98
|
+
koda_headers_middleware(app)
|
|
99
|
+
app.mount("/", a2a_server.to_fastapi_app())
|
|
100
|
+
|
|
101
|
+
logger.info(
|
|
102
|
+
"agent app built: name=%s version=%s tools=%d peers=%d",
|
|
103
|
+
cfg.name,
|
|
104
|
+
cfg.version,
|
|
105
|
+
len(tools),
|
|
106
|
+
len(cfg.peers),
|
|
107
|
+
)
|
|
108
|
+
return app
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def load_skills_for_agent(base_dir: Path) -> str:
|
|
112
|
+
"""Resuelve las skills del agente según el flag ``KODA_SKILLS_SOURCE``.
|
|
113
|
+
|
|
114
|
+
- ``offline`` (default): lee ``skills/<name>/SKILL.md`` del disco y devuelve
|
|
115
|
+
un bloque para anexar al system prompt. Ideal para desarrollo — sin
|
|
116
|
+
registry, sin bearer.
|
|
117
|
+
- ``registry``: devuelve cadena vacía; en este modo las skills se resuelven
|
|
118
|
+
en runtime con la tool ``fetch_registry_skill`` (que necesita el JWT del
|
|
119
|
+
caller por-request). No se inyectan en el arranque.
|
|
120
|
+
|
|
121
|
+
Nombres de skill: ``koda-skill-<fase>-<target>``.
|
|
122
|
+
"""
|
|
123
|
+
source = os.environ.get("KODA_SKILLS_SOURCE", "offline").strip().lower()
|
|
124
|
+
if source == "registry":
|
|
125
|
+
logger.info("KODA_SKILLS_SOURCE=registry: skills vía fetch_registry_skill en runtime")
|
|
126
|
+
return ""
|
|
127
|
+
if source != "offline":
|
|
128
|
+
logger.warning("KODA_SKILLS_SOURCE=%r no reconocido; usando 'offline'", source)
|
|
129
|
+
|
|
130
|
+
skills_dir = base_dir / "skills"
|
|
131
|
+
if not skills_dir.is_dir():
|
|
132
|
+
return ""
|
|
133
|
+
parts: list[str] = []
|
|
134
|
+
for skill_md in sorted(skills_dir.glob("*/SKILL.md")):
|
|
135
|
+
try:
|
|
136
|
+
content = skill_md.read_text(encoding="utf-8").strip()
|
|
137
|
+
except OSError as exc:
|
|
138
|
+
logger.warning("no pude leer skill %s: %s", skill_md, exc)
|
|
139
|
+
continue
|
|
140
|
+
if content:
|
|
141
|
+
parts.append(content)
|
|
142
|
+
if not parts:
|
|
143
|
+
return ""
|
|
144
|
+
joined = "\n\n---\n\n".join(parts)
|
|
145
|
+
return (
|
|
146
|
+
"# Skill(s) aplicables (cargadas localmente, modo offline)\n\n"
|
|
147
|
+
"Sigue estas guías al pie de la letra para tu fase. No necesitas "
|
|
148
|
+
"buscar skills en el registry: ya están aquí.\n\n"
|
|
149
|
+
f"{joined}"
|
|
150
|
+
)
|