feat(build): let --build-context replace the runtime image
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 45/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- docker, go
- Domain
- build-system, devops
Research direction
Start with pkg/build/build.go, pkg/build/context.go, and pkg/agentkit2llb/agent/convert.go to trace how the runtime image becomes the LLB base; check BuildKit's dockerui.NamedContext API for loading a named context per platform. Then review pkg/build/build_test.go and the agent LLB tests, and run go test ./... and make lint. Done means the context and conflict behavior are tested, the bake targets and both docs are updated, and existing Makefile targets still work.
Written by the indexing model from the issue text.
Description
Problem
Every agent image starts from a runtime image, for example ghcr.io/orka-agents/agentkit/serve-pydantic-ai:latest. Today the only way to use a different one is --build-arg adapter=<image>. That has to be an image BuildKit can download, or one in Docker's local image store when you use Docker's default builder.
This causes four problems:
- The dev loop needs
--load.make build-servebuilds the runtime image and loads it into Docker asagentkit-serve:test.make build-test-agentthen points at it withadapter=agentkit-serve:test.- This only works with Docker's default builder. A container or remote builder (
docker buildx create ...) can't see local images, so you must push the runtime image to a registry first.
- No offline option. You can't use a runtime image saved in a local folder (an OCI layout) without running a registry.
- Mirrors are awkward. Teams that mirror images have to pass the full mirror image name on every build, outside Docker's usual way of swapping images.
- Tests can't easily use a fresh runtime image. Integration tests (#65) need to use a runtime image they just built, without pushing it anywhere.
Docker's standard answer is named build contexts: --build-context <name>=<source>. The source can be:
docker-image://<image>: another image, for example from a mirror;oci-layout://<folder>@sha256:<digest>: an image saved in a local folder, with no registry;target:<name>in adocker buildx bakefile: an image built earlier in the same bake run.
The Dockerfile frontend uses this to swap FROM images. dalec uses it to swap its build images (see dalec's targets docs, section "Named Build Contexts").
What
AgentKit looks for a build context named agentkit-runtime. If one is given, it's used as the runtime image instead of downloading the default.
# Use a mirror
docker buildx build -f agentkitfile.yaml . \
--build-context agentkit-runtime=docker-image://mirror.example.com/agentkit/serve-pydantic-ai@sha256:<digest>
# Use an image saved in a local folder, no registry needed
docker buildx build -f agentkitfile.yaml . \
--build-context agentkit-runtime=oci-layout://./serve-pydantic-ai@sha256:<digest>
- Multi-platform builds work. BuildKit also allows a separate context per platform (
agentkit-runtime::linux/arm64), and itsdockeruihelper handles this automatically. - No silent winner. If both
--build-context agentkit-runtimeand--build-arg adapterare given, fail with a clear message. - Settings unchanged. The image settings AgentKit writes stay the same. AgentKit already writes its own entrypoint, user, env and labels instead of copying them from the runtime image.
- One-command dev loop. Add a
docker-bake.hclso the runtime image and a test agent build together on any builder, without--load:
The AgentKit frontend image (target "serve-pydantic-ai" { dockerfile = "runtimes/pydantic-ai/Dockerfile" } target "test-agent-pydantic-ai" { dockerfile = "test/agentkitfile-hello.yaml" contexts = { agentkit-runtime = "target:serve-pydantic-ai" } args = { BUILDKIT_SYNTAX = "agentkit:test" } }BUILDKIT_SYNTAX) still has to be reachable by the builder. On a remote builder, that means pushing it to a registry. Swapping the frontend image itself is not part of this issue.
Out of scope
- Checking that the given image really is a runtime image for the file's runtime.
adapter=isn't checked today either. - Accepting the default image's own name as the context name, as dalec and Dockerfiles do. It's a possible follow-up.
- Changes to PR #52 (separate base and harness images). That PR could use the same mechanism for its two images, for example
agentkit-baseandagentkit-harness.
Why
- The dev loop works on any builder, including remote ones, without
--loador pushing runtime images. - Builds work offline from a local image folder.
- It uses the mechanism Docker users already know for swapping images.
- Integration tests (#65) can test fresh, unpushed runtime images.
How
Where things are
| File | What it does |
|---|---|
pkg/build/router.go |
RuntimeConfig.AdapterRef(opts) returns the adapter build arg or the default runtime image. |
pkg/build/build.go |
handleAgent() gets the runtime image name, then buildImage() builds each platform. |
pkg/agentkit2llb/agent/convert.go |
Agentkit2LLB(agent, adapterRef, platform) starts from llb.Image(adapterRef, llb.Platform(*platform)) and adds /agent/agent.yaml. |
pkg/build/context.go |
Already uses BuildKit's dockerui package. |
BuildKit frontend/dockerui/config.go |
(*dockerui.Client).NamedContext(name, dockerui.ContextOpt{Platform: p}) returns nil when no such context was given. (*NamedContext).Load(ctx) returns the image as an *llb.State. |
Makefile |
build-serve, build-test-agent and friends. Keep them working. |
Steps
- Look for the context. In
buildImage()(once per platform):- create
bc, err := dockerui.NewClient(c)and callbc.NamedContext("agentkit-runtime", dockerui.ContextOpt{Platform: platform}); - if it isn't
nil, callLoad(ctx)and use the returned state as the base. - Create the
dockeruiclient once and pass it down rather than creating one per platform.
- create
- Pass a starting point, not a name. Change
Agentkit2LLBto take the basellb.Stateinstead of an image name. Callers buildllb.Image(adapterRef, llb.Platform(...))themselves when no context was given. Leave the image settings code as it is. - Conflict check. If the context and the
adapterbuild arg are both set, return an error naming both. - Bake file.
- Add
docker-bake.hclwith a runtime-image target for each runtime and a test-agent target for each runtime, wired together withcontexts. - Mention it in
docs/development.md. Keep the existing make targets working.
- Add
- Name in one place. Keep the context name as a constant in
pkg/utils/const.gonext to the other build constants.
Tests
- Unit tests (
pkg/build/build_test.go,pkg/agentkit2llb/agent):- with no context, the base is the default runtime image, as today;
- with both the context and
adapter, the build fails with a clear message; Agentkit2LLBuses the given base state.
- End to end:
docker buildx bake test-agent-pydantic-aion adocker-containerbuilder (docker buildx create --driver docker-container --use) builds without loading or pushing the runtime image;- export a runtime image to a folder (
--output type=oci,dest=./serve,tar=false) and build an agent from it withoci-layout://; - a two-platform build with a context per platform.
- Integration tests: once #65 exists, add a real-BuildKit test there.
Run:
go test ./...
make lint
Docs
docs/agentkitfile.md, where it describes--build-arg adapter: add--build-context agentkit-runtime=...with the mirror and local-folder examples, plus the conflict rule.docs/development.md: the bake-based dev loop.
Done when
--build-context agentkit-runtime=<source>works withdocker-image://andoci-layout://sources, and with baketarget:sources.- Multi-platform builds work with per-platform contexts.
- Giving both the context and
adapterfails with a clear message. - The bake dev loop builds a test agent on a
docker-containerbuilder without--loadand without pushing the runtime image. - The docs cover the new option and the dev loop.
- Dominant language
- Python
- Stars
- 7
- Forks
- 5
- Avg merge
- 3h 39m
- Merged PRs (30d)
- 1
Getting set up
- Ships a Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from orka-agents/agentkit
-
fix(pydantic-ai): CI fails with newest pydantic-ai (unexpected 'history' argument)Possibly taken @gambtho claimed this 30 days ago. Open
Difficulty 3/5 1-2 days Newbie friendliness 35/100
orka-agents/agentkit#77 ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
orka-agents/agentkit#76 · 3 comments ·
-
area/build area/orka area/runtime blocked enhancement
Difficulty 4/5 3-5 days Newbie friendliness 45/100
orka-agents/agentkit#69 ·
-
area/build area/orka area/runtime enhancement
Difficulty 4/5 3-5 days Newbie friendliness 68/100
orka-agents/agentkit#68 ·
-
area/build enhancement testing
Difficulty 5/5 Over a week Newbie friendliness 42/100
orka-agents/agentkit#65 ·
All issues in orka-agents/agentkit
Similar issues
-
enhancement
Difficulty 1/5 Under an hour Newbie friendliness 62/100
DaoCloud/DaoCloud-docs#7839 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
sav-oss-org/ptusa_main#1610 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
bug status/accepted type/bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
microsoft/apm#4925 · 1 comment ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
sagemathinc/sagebrush#1701 ·
Maintainers usually reply within 1 day