Skip to main content

Reusable runtime, config loader and bootstrap for KODA-ecosystem A2A agents on Amazon Bedrock AgentCore.

Project description

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
  model_id: us.amazon.nova-lite-v1:0
  temperature: 0.3
  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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

koda_agent_runtime-0.1.3.tar.gz (112.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

koda_agent_runtime-0.1.3-py3-none-any.whl (19.0 kB view details)

Uploaded Python 3

File details

Details for the file koda_agent_runtime-0.1.3.tar.gz.

File metadata

  • Download URL: koda_agent_runtime-0.1.3.tar.gz
  • Upload date:
  • Size: 112.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.22

File hashes

Hashes for koda_agent_runtime-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f86f1fb360a6a42bc264f383c2a53831dd204b304b1d75807422945d539a09ff
MD5 af506ff0ebbba0bf09b46be949837fc7
BLAKE2b-256 141272209542bfd2e79c581a14602904018f695f2832efbbe65859b227bea9bd

See more details on using hashes here.

File details

Details for the file koda_agent_runtime-0.1.3-py3-none-any.whl.

File metadata

File hashes

Hashes for koda_agent_runtime-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 55359f105a10014eb7e3a34383ad6c85fa9a05e542087c51d692b2d44758d301
MD5 963bff0766a0a92712e07c9c1cd9d3cc
BLAKE2b-256 d5cc2597076e78a3410074c0825ac2ef83cb9df956842c29e9ec6cf6fb592fb3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page