Skip to content

Document the BYO agent contract, and forward a session identifier to the model #2884

Open

Description

@ishangupta-ds

Summary

kagent runs "bring your own" agents (Agent with type: BYO) as long as the image serves A2A the way kagent expects. That expectation isn't written down anywhere we could find — we reverse-engineered it from kagent 0.9.x while building a Kubernetes control plane that runs kagent-routed, sandboxed and BYO agents behind one gateway.

Two asks: document the contract, and forward a session identifier to the model.

1. The BYO contract, as we found it

These are the requirements our harnesses had to satisfy before kagent would route to them. We'd be glad to see them in kagent's docs in any form; the numbering is only for reference here.

Discovery

  1. GET /.well-known/agent-card.json returns 200 with a JSON object.
  2. The card carries name, description, version, and skills (an array, possibly empty).
  3. The card advertises the address clients should invoke — a top-level url (A2A v0.3) or supportedInterfaces[].url (A2A v1.0). When something fronts the agent, this must be the externally reachable address, not the pod's. This is the requirement that cost us the most time: a card advertising its own in-cluster address is silently unroutable from outside, and nothing reports an error.
  4. The card should carry protocolVersion and defaultInputModes/defaultOutputModes.

Invocation
5. POST / with a JSON-RPC 2.0 message/send returns a JSON-RPC 2.0 response whose id echoes the request's, carrying result (not error) on success.
6. The result is an A2A Message ("kind": "message", "role": "agent", at least one text part) or an A2A Task ("kind": "task") whose artifacts or history carry the agent's text.
7. An unknown method returns JSON-RPC error -32601.
8. A malformed request returns -32700.

Requirements 1–3 and 5–6 are the ones that actually gate interoperability; 4, 7 and 8 are quality-of-implementation.

2. Standardize how a BYO agent is configured

Today each platform invents its own environment for a BYO image. If kagent documented (or adopted) a small set of variables — model base URL, model name, system message, public URL, and per-tool URL/credential — one image could run under kagent and under any other platform that speaks the same contract, with no image changes. We're not attached to our names; we care that there is one set.

3. Forward a session identifier to the model

A Declarative agent's model calls currently carry no session identity. Anything metering model spend therefore cannot attribute cost per conversation for kagent-routed agents — only per agent. A single header forwarded from the A2A request to the model call (x-session-id, or whatever name kagent prefers) would close that gap.

This is the one we'd most like, and we're happy to implement it if you point us at the preferred place in the model client.

Evidence

We run an end-to-end suite on kind against kagent 0.9.12. A Declarative kagent agent, a Go BYO harness and a Python BYO harness all satisfy every requirement above, through a gateway that rewrites discovery. We verify each requirement with an executable checker rather than by inspection, so the list above is machine-checked, not aspirational.

Happy to share the checker, the harnesses, or a reproduction in whatever form is useful — say the word and we'll paste it here.

Questions for maintainers

  • Would you accept a written BYO contract in kagent's docs? We'll open the PR if the shape above is close.
  • Is there appetite for (3)? It's small, and it unblocks per-session cost attribution for every platform building on kagent.
  • Is requirement 3 (the externally-reachable url) intentional and stable? We depend on it; it would be good to know it's a contract rather than an accident.

Activity

  1. ishangupta-ds commented on Sep 22, 2026

    @ishangupta-ds
    Author

    A follow-up with new information, after reading the v1.0.0-alpha1 CRDs.

    The new Harness kind makes this proposal more concrete than when I filed it. Its byo runtime is described in the CRD as:

    BYOHarness selects an image that implements kagent's private A2A contract.

    That is the contract this issue asks to document, and Harness.byo now looks like its natural home. The eight requirements in the issue body are still the draft I'd offer for that text; a Go BYO harness and a Python one both satisfy them today through 0.9.x, and I'd expect them to against v1 unchanged if the contract is what we reverse-engineered.

    Mapping our current Agent (0.9/0.10, v1alpha2) rendering onto AgentTemplate + Harness (v1alpha3), everything has an obvious home except two things, which I think are worth raising while the shape is still alpha:

    1. Per-template configuration for a BYO harness. Harness.spec.env is per runtime, shared by every template the harness serves. A BYO image that needs to know which agent it is — its public URL for the card's url, a system message, tool endpoints or credentials — has nowhere per-template to learn it. AgentTemplate has systemPrompt and tools for the kagent runtime, but nothing a BYO image can read. Either an AgentTemplate.spec.env, or a documented convention for how a BYO runtime discovers its template at request time, would close this.

    2. Where replicas went. Agent.spec.declarative.deployment.replicas / byo.deployment.replicas have no counterpart; capacity seems to live entirely in substrate.workerPoolRef now. If sizing is intentionally a pool property rather than a per-agent one, saying so explicitly would save platforms that size per agent from looking for it.

    Item 3 from the original issue (forwarding a session identifier to the model) still applies — nothing in v1alpha3 addresses it as far as I can see.

    Two things I noticed and don't need anything for, just flagging that they overlap with what a platform on top of kagent would otherwise build: isolateSessions (#2504) and tools[].mcp.requireApproval. Glad to see both.

  2. ishangupta-ds commented on Sep 24, 2026

    @ishangupta-ds
    Author

    Follow-up after running 1.0.0-alpha2 end to end (Substrate 0.2.0-beta5 on kind, a platform operator rendering AgentTemplate + Harness{kagent} and driving AgentInstanceService + A2A gRPC from outside). Everything below is from the running system, not the CRDs. Sharing in case any of it is useful as you shape 1.0:

    1. The BYO contract, as compiled. For Harness.byo the ActorTemplate ends up as: digest-pinned image, explicit workload.command, A2A gRPC on port 80, readiness HTTP /readyz on 8081, env = spec.env + KAGENT_CONFIG_JSON + KAGENT_AGENT_CARD_JSON + trust-bundle vars (≤32 vars), credentials never in env (egress injection by hostname). Would you consider documenting exactly this on the CRD instead of "private"? It is what anyone bringing a harness has to hit. Related: is an HTTP JSON-RPC binding for BYO harnesses on the table, or is gRPC-only the intended 1.0 contract?

    2. Per-template env. Harness.spec.env is per harness, KAGENT_CONFIG_JSON is per pair. A harness admitting many templates has no way to give one template one extra env var (say a tenant-specific base URL). Is a spec.env-shaped field on AgentTemplate something you would take?

    3. Credential injection over plain http:// works — confirmed with an in-cluster OpenAI-compatible proxy on :4000 with no TLS: the ModelConfig key was added by the egress gateway and the proxy saw it. Worth a line in the docs, since people will assume injection needs TLS.

    4. WorkerPool per template namespace. substrate.workerPoolRef resolves in the AgentTemplate's namespace: WorkerPool "<ns>/kagent-default" not found when the pool lives in kagent/. Every namespace that hosts templates needs its own pool (and credential-provider policy). Intentional as a tenancy boundary? If so a workerPoolRef.namespace or a documented "one pool per namespace" would save people the hunt.

    5. replicas → WorkerPool sizing. With no per-agent Deployment, the old deployment.replicas has no home; the closest is WorkerPool.spec.replicas. Fine by us, but worth a migration note for 0.10 users.

    6. Declarative / idempotent AgentInstance creation. CreateAgentInstance is idempotent on request_id, which is enough for a controller, but instances are only reachable through gRPC and are creator-scoped by x-user-id. A platform that brokers instances on behalf of many users has to pick one principal for all of them. Is an AgentInstance CRD (or a service-principal concept) planned?

    7. Two things that cost us a day each, in case they are worth a doc line: forwarding the client's context_id in SendMessage is rejected (message context does not match AgentInstance) — the instance owns the context; and unary SendMessage returns a submitted Task with no output (also after GetTask), so a client has to use SendStreamingMessage and fold the artifact events. Also: the Go ADK requests stream: true from the model, and an OpenAI-compatible backend that ignores it produces an empty reply through some proxies (LiteLLM fake-streams one empty delta).

  3. added
    stale
    on Nov 23, 2026
  4. ishangupta-ds commented on Nov 24, 2026

    @ishangupta-ds
    Author

    Still relevant, and I'd like to keep it open. Here's an update now that 1.0 has shipped. We've run kagent 1.0.0 with Substrate 1.0.0 since GA as the runtime under a platform operator. That operator renders Harness + AgentTemplate + Agent under api.kagent.dev/v1alpha3 and opens one Session per conversation over SessionService. A byo harness on it takes its config through KAGENT_BOOTSTRAP_JSON / config.MaterializeFromBootstrap.

    What 1.0 already answered, so I'm dropping these:

    • Per-template config for a byo harness (my Sept follow-up, item 2). The bootstrap bundle is per Agent revision, so a byo runtime does learn which agent it is. That covers us.
    • Where replicas went. Capacity belongs to the WorkerPool now. Clear enough from the design.

    What's still open:

    1. Document the byo contract. In v1.0.1, BYOHarness is still described as implementing "kagent's private A2A contract". From running it, this is what a byo image has to satisfy:

      • a digest-pinned workload.image with an explicit workload.command
      • A2A v1.0 over gRPC on :80, with readiness on HTTP /readyz :8081
      • config loaded from KAGENT_BOOTSTRAP_JSON (fetch the bundle, verify its sha256)
      • A2A-Version: 1.0 on calls (a2a-go 2.7 treats a missing header as 0.3)
      • credentials arriving as a placeholder that Substrate's egress gateway replaces, never as env values

      Is go/adk/examples/byo meant to be the reference for that? If so, I'd open a docs PR that writes the list above next to it. (The eight JSON-RPC requirements in the original issue describe 0.9.x. Treat them as superseded for 1.0.)

    2. A session identifier on model calls. Still not there as far as I can see. We work around it: a per-session model key sent as the A2A bearer, with tokenPassthrough. But that only works when every caller goes through a gateway that mints keys. A forwarded header such as x-kagent-session-id on the model request would let anything metering model spend attribute cost per session directly. I'm happy to implement it if you point me at the model client you'd want it in.

    3. A question, not a request: is the byo/AgentTemplate tool rule (self.kind == 'RemoteMCPServer') and the @sha256-only image pattern meant to stay for 1.x? We route harnesses that need other tool kinds or tag-pinned images elsewhere. Knowing whether that's permanent would settle how we plan around it.

    If it helps, I'd also be glad to retitle this to "Document the 1.0 byo harness contract, and forward a session id to the model".

  5. removed
    stale
    on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions