Skip to main content

koda-agent-runtime

Runtime compartido para agentes Koda A2A sobre Amazon Bedrock AgentCore. Extrae en un solo paquete versionado las piezas que cada koda-agent-* repite: constantes de custom headers, middleware FastAPI, cliente HTTP hacia el registry, decoradores de tools, loader del agent.yaml, y un bootstrap build_agent_app(cfg) que ensambla Strands + A2A + FastAPI en una llamada.

Ver KODA_AGENT_RUNTIME_ARCHITECTURE.md en el monorepo koda-platform para el diseño completo, precedente (koda-mcp-access), roadmap y compatibilidad.

Instalación

Elige el extra según lo que consuma el agente:

# El mínimo — headers, middleware, registry client, config loader.
"koda-agent-runtime>=0.1.2,<0.2"

# El agente típico — además Strands + A2A + Bedrock (y AnthropicModel) para
# build_agent_app.
"koda-agent-runtime[bootstrap]>=0.1.2,<0.2"

# El stack CDK del agente — Construct KodaAgentRuntime.
"koda-agent-runtime[cdk]>=0.1.2,<0.2"

El extra bootstrap instala strands-agents[a2a,anthropic], de modo que build_agent_app soporta tanto provider: bedrock como provider: anthropic (este último vía AnthropicModel, con ANTHROPIC_API_KEY en el entorno).

Uso — un agente en 10 líneas

src/agent.py:

from pathlib import Path
import uvicorn
from koda_agent_runtime.config import load_agent_config
from koda_agent_runtime.app import build_agent_app

_BASE = Path(__file__).resolve().parent.parent
app = build_agent_app(load_agent_config(_BASE / "agent.yaml"), base_dir=_BASE)

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=9000)

agent.yaml:

name: koda-agent-example
version: 0.1.0
description: |
  Un agente de ejemplo.

model:
  provider: bedrock              # bedrock | anthropic
  model_id: us.amazon.nova-lite-v1:0
  temperature: 0.3               # opcional; OMITIR en modelos que la tienen
                                 # deprecada (Sonnet 5, Opus 4.8) o dan error
  max_tokens: 4000

tools:
  - discover_skills
  - fetch_registry_skill
  - invoke_agent

Módulos

Módulo Responsabilidad
koda_agent_runtime.headers Constantes KODA_*_HEADER + ALLOWLISTED_HEADERS (para agentcore configure --request-header-allowlist).
koda_agent_runtime.context Module-level _state con bearer y request_id; set_context, get_bearer, get_request_id.
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.
koda_agent_runtime.registry discover_agents, discover_skills, fetch_skill_bundle, invoke_peer — hablan con el registry usando el bearer del state.
koda_agent_runtime.tools Decoradores @strands.tools.tool sobre los helpers de registry. build_tools(cfg) filtra por lo declarado en agent.yaml.tools.
koda_agent_runtime.config load_agent_config(path) → dataclass tipado AgentConfig.
koda_agent_runtime.app build_agent_app(cfg, base_dir) → FastAPI con Strands Agent + A2AServer + middleware montados. Requiere [bootstrap] extra.

Contrato de headers Koda-*

koda-proxy (broker del registry) inyecta 8 custom headers al invocar tu runtime. AgentCore solo forwardea headers con prefix X-Amzn-Bedrock-AgentCore-Runtime-Custom-.

Header Contenido Estable en cadenas A→B→C
Koda-Authorization Bearer JWT vigente (Okta o self-signed 8h). No — se refresca cuando expira.
Koda-Sub Usuario humano original. Sí.
Koda-Email Email del usuario. Sí.
Koda-Roles Groups Okta del usuario. Sí.
Koda-Chain-Depth Hops desde el usuario. +1 por hop.
Koda-Request-Id uuid para trace end-to-end. Sí.
Koda-Agent-Path Path del agente que recibe. N/A.
Koda-Caller-Type user | agent. Depende del hop.

Todos los strings viven en koda_agent_runtime.headers como constantes. Nunca los repitas en tu código.

Anti-patrones

  • No uses contextvars.ContextVar para propagar el bearer entre middleware y tools: Strands corre tools en threads distintos al request handler; el ContextVar aparece vacío. Usa set_context().
  • No firmes SigV4 desde el agente para invocar peers. Delega via invoke_peer(<path>, <msg>) — el registry firma por ti.
  • No llames set_context() en el middleware si no hay bearer. Los /ping de AgentCore te borrarían el state que otra request iba a usar.

Desarrollo

uv sync --dev
uv run pytest
uv run ruff check src/
uv build

Release: bump pyproject.toml, tag vX.Y.Z, push tag.

Versionado

  • v0.x — alpha, breaking changes tolerados. Todos los agentes en migración inicial.
  • v1.0.0 — cuando la API sea estable y >=3 agentes la consuman en producción. A partir de acá, SemVer estricto.

Metadata

Release files for koda-agent-runtime 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for koda-agent-runtime 0.1.4
File Size Uploaded Provenance Actions
koda_agent_runtime-0.1.4.tar.gz 113.3 kB Without provenance Details for koda_agent_runtime-0.1.4.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for koda-agent-runtime 0.1.4
File Interpreter ABI Platform Actions
koda_agent_runtime-0.1.4-py3-none-any.whl Python 3 none any Details for koda_agent_runtime-0.1.4-py3-none-any.whl

Total release size: 132.8 kB

Release files / koda_agent_runtime-0.1.4.tar.gz

Download URL koda_agent_runtime-0.1.4.tar.gz
Size 113.3 kB
Tags Source
SHA-256 checksum
How to use checksums
799fa825425750fb4c1ac0960e44b2bf7ef93f23e6a71e8b9304ddf08d593523
BLAKE2b-256 checksum
How to use checksums
057c71ca21eac059e66b4231c79fc3e21ccfb9c1dc9980e5477ba5b568b6b2f5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Release files / koda_agent_runtime-0.1.4-py3-none-any.whl

Download URL koda_agent_runtime-0.1.4-py3-none-any.whl
Size 19.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
4db917f3e1b52f048753f83738ee65013e60bb9d3fd1283bf2293eb62a7c9fab
BLAKE2b-256 checksum
How to use checksums
069e012c7cf899bc343587d9fc0e7df33534ba1894195122d362e9451ec23a37
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.8.22

Security for koda-agent-runtime 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page