feat(build): run agent tests during the image build
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Active
- Domain
- build-system, devtools
Research direction
Start by reading pkg/agentkit/config/specs.go and validate.go for the schema, then trace how agents reach pkg/agentkit2llb/agent/convert.go. The issue lays out Go, Python, BuildKit, CI, and documentation work; implementation and tests are needed across those areas, with passing and failing builds verifying the feature.
Written by the indexing model from the issue text.
Description
Problem
There is no simple way to check that an AgentKit image works before you ship it.
Many build mistakes only show up after the container is deployed and someone sends a request:
- an instructions file that wasn't included;
- a tool that crashes when it starts, or doesn't offer the tools the agent expects;
- a tool env var that never reaches the tool;
- a tool result that never makes it back to the model.
The AgentKit repo checks its own images with hand-written smoke scripts (test/*-image-smoke.py, scripts/parity-container-smoke.sh). People who build their own agents have nothing like that.
AgentKit has no CLI, so a separate agentkit test command isn't an option. Everything happens through docker buildx build.
What
Let people add a tests: list to their Agentkitfile. AgentKit runs these tests while it builds the image. If a test fails, the build fails.
This copies how dalec does it. Dalec is another BuildKit frontend, and its tests: section runs checks against the image it just built (see dalec's tests.go, frontend/test_runner.go and internal/testrunner/).
Tests use a fake model: the test lists the model's replies in order, and AgentKit plays them back. So tests:
- need no API key and no network;
- give the same result every time, which makes them safe to cache;
- run the agent's real tools inside the real image.
tests:
- name: starts and offers the stock tools
prompt: hi
model:
- content: hello
expect:
toolsOffered: [inventory_get_stock, inventory_reserve_stock]
- name: answers from the stock tool
prompt: How many LAMP-1001 do we have?
model: # fake model replies, played in order
- toolCalls:
- name: inventory_get_stock
arguments: {sku: LAMP-1001}
- content: We have 12 in stock.
expect:
toolCalls:
- name: inventory_get_stock
status: completed
result: # what the tool sent back to the model
contains: ["12"]
response:
contains: ["12"]
Fields
Each test:
| Field | Required | Meaning |
|---|---|---|
name |
yes | Unique test name, shown in the build output. |
prompt |
yes | The user message to send. |
model |
yes | The fake model's replies, in order. Each reply has either content (a final answer) or toolCalls (the tools to call). |
env |
no | Values for env vars the agent declares, for example a tool setting. These are written into the Agentkitfile, so never put real secrets here. Names starting with AGENTKIT_ aren't allowed. |
expect |
no | The checks to run. With no checks, the test only proves the agent starts and finishes. |
Checks under expect:
| Check | What it checks |
|---|---|
toolsOffered |
The first request to the model listed these tool names. This proves the tools started. |
toolCalls |
Tools that ran, by name and status (completed or failed), with an optional result check on the text the tool returned. |
response |
The agent's final answer. |
Text checks work on response and result. The names match dalec's, in AgentKit's camelCase style: equals, contains, matches (a regular expression), startsWith, endsWith, empty.
Tool names are what the model sees: <tool name>_<MCP tool name>, for example inventory_get_stock. The parity tests already require all three runtimes to use this format.
Behavior
- Network off, normal user. Tests run inside the built image with no network access, as user 1000, the same user the real container uses.
- Image unchanged. Tests are not written into
/agent/agent.yamlor anywhere else in the image. - Cached. Results are cached like any other build step, so an unchanged file doesn't rerun its tests.
--no-cache-filter agentkit.testsforces a rerun. - Can be skipped.
--build-arg AGENTKIT_SKIP_TESTS=1skips tests and prints a warning. - Readable failures. A failure names the test and the check, and shows what was expected and what came back, cut down if it's long. It never prints env values.
- Remote MCP tools and context providers are switched off during tests. They can't be reached during a build. The docs should say so.
Out of scope
- Checking answer quality with a real model. That needs secrets and network, and gives different results each time, so it doesn't belong in a cached build. The live task-success evals and tools like promptfoo cover it.
- Running tests only on the native platform. In a multi-platform build, tests run once per platform, the same as in dalec. A "native platform only" option can come later.
- Multi-turn conversations. Prior chat history in a test can come later.
Why
- Mistakes fail the build instead of failing in production.
- People can test their agent without a separate tool or CLI. It's part of
docker buildx build, which they already run. - Every test runs the real image, with its real tools and real runtime.
- Tests are free and fast: no API key, no model cost, no network.
- The AgentKit repo can use it too. Some hand-written image smoke scripts could become
tests:blocks.
Depends on
- #54 (install tool packages when the image is built). Tests run with network off, so stdio tools started with
uvxornpxcan't download themselves. If a tool fails to start during a test, the error should suggestpackagefrom #54. Tests that don't use stdio tools work without #54.
How
Where things are
| File | What it does |
|---|---|
pkg/agentkit/config/specs.go, validate.go |
Agentkitfile schema and checks. Add Tests here. |
pkg/agentkit/effective/agent.go |
The build-ready agent. Carry the tests through to the build. |
pkg/agentkit/abi/render.go |
Writes /agent/agent.yaml. Tests must not be written there. |
pkg/agentkit2llb/agent/convert.go |
Turns the agent into BuildKit build steps: the runtime image plus /agent/agent.yaml. Add the test steps here. |
pkg/build/build.go |
Reads build args and options. AGENTKIT_SKIP_TESTS and the cache filter are read here. |
runtimes/common/agentkit_serve_common/cli.py |
agentkit-serve startup. Add a --self-test option here. |
runtimes/common/agentkit_serve_common/parity.py |
Has _ScriptedProvider, a fake Chat Completions server that uses only the Python standard library. It replays replies and records every request, including stream: true requests. Reuse it. |
runtimes/common/agentkit_serve_common/runtime.py, conversation.py |
RuntimeSession.run(), RunRequest and its on_tool_event callback. The test runner uses these directly. |
Steps
1. Schema and validation (Go). Add a tests: list with the fields above. The build should fail with a clear message when:
- a name is missing, repeated, or uses characters that can't appear in build output;
- the prompt is empty;
- a
modelreply sets both or neither ofcontentandtoolCalls; - the last
modelreply isn'tcontent, so the run could never finish; - a regular expression doesn't compile;
- an
envname isn't declared by the agent, or starts withAGENTKIT_; - a check object is empty.
2. Test runner (Python).
- Move the fake model out of
parity.pyinto its own module, for exampleagentkit_serve_common/fake_model.py. It should replay a fixed list of replies. Haveparity.pyimport it from there. - Add
--self-test <path>toagentkit-serve. When it's set, run the tests in that file and exit instead of starting a server. Put the logic in a new module such asagentkit_serve_common/selftest.py. - For each run:
- Load the real
/agent/agent.yaml. - Make a copy of the agent settings in memory with:
- the model address pointed at the fake model on
127.0.0.1; - remote MCP tools and context providers removed;
- dummy values for declared env vars, unless the test sets them.
- the model address pointed at the fake model on
- Build the runtime with the adapter's
agent_factory.build_runtime(spec). Run the prompt withRunRequest(prompt=..., on_tool_event=...)and record the tool events. - Check the results:
toolsOffered: from thetoolslist in the first request the fake model received;- tool
result: from the tool messages in later requests; response: from the run's final text.
- Print one line per check. Exit 1 if any check fails.
- Load the real
- Pointing the model at a fake server must only happen inside
--self-test. It must never become an env var or setting that a real deployment could use.
3. Build steps (Go). In convert.go, after /agent/agent.yaml is written, add one step per test on top of the finished image:
- Command:
/opt/agentkit/bin/agentkit-serve --config /agent/agent.yaml --self-test /tmp/agentkit-test/test.json, passed as a list withllb.Args(...). - Test file: write the test as JSON into an empty filesystem (
llb.Scratch().File(llb.Mkfile(...))) and mount it read-only. - No network:
llb.Network(llb.NetModeNone). - User:
llb.User("1000:1000"). - Build output: show each test as
Test: <name>withllb.ProgressGroup. - Force rerun: if
dockerui.NewClient(c).IsNoCache("agentkit.tests"), addllb.IgnoreCache. Dalec does this infrontend/test_runner.go. - Skip: if
AGENTKIT_SKIP_TESTSis true, skip the steps and print a warning. See how dalec does this infrontend/test_runner.go.
4. Make the build wait for the tests without changing the image.
- A test step's output must not become part of the image.
- Copy dalec's trick in
internal/testrunner/step.go(noopCommand.WithOutput): run a step that does nothing, mount every test result into it read-only, and return the original image unchanged as that step's output. BuildKit then has to run all the tests before it can finish the image. - The comments in dalec's code explain why the output mount must stay writable.
- Check that the image layers are the same as in a build with
AGENTKIT_SKIP_TESTS=1.
Tests for this feature
- Go, config: one test for each validation rule.
- Go, build steps (
pkg/agentkit2llb/agent):- each test becomes a step with network off, user 1000, the right command and the mounted JSON;
AGENTKIT_SKIP_TESTS=1removes those steps;- the cache filter adds
IgnoreCache; /agent/agent.yamldoesn't change when tests are present.
- Python: shared self-test cases that every runtime runs, the same way
parity.pyandconformance.pyare shared, using the MCP probe server already inparity.py. Cover:- passing checks;
- each kind of failing check, with a readable message;
- the fake model running out of replies;
- a tool that fails to start.
- End to end:
- Add a fixture
test/agentkitfile-selftest.yamlwith passing tests, and one with a test that should fail. - Build both in the CI Docker job. Check that the first build succeeds and the second fails with a message that names the failing test.
- Run actionlint after editing workflows (see
AGENTS.md).
- Add a fixture
Run:
go test ./...
make lint
uv run --directory runtimes/common --extra dev pytest -q
cd runtimes/<runtime> && python -m pytest -q # pydantic-ai, microsoft-agent-framework, langgraph
Docs
docs/agentkitfile.md: add a "Tests" section covering:- the fields, checks and tool-name format;
- that tests run without network and with a fake model;
- how to skip tests or force them to rerun;
- that remote tools and context providers are switched off;
- what tests don't cover (answer quality), with a pointer to live evals.
README.md: add a short "Test your agent while it builds" section with the example above.
Done when
- A build with passing
tests:succeeds. - A build with a failing test fails, and the message names the test, the check, what was expected, and what came back.
- Tests run with network off and as user 1000.
- An unchanged file reuses cached test results.
--no-cache-filter agentkit.testsreruns them.AGENTKIT_SKIP_TESTS=1skips them with a warning. - Tests leave no trace in the image.
/agent/agent.yamland the image layers are the same as in a build without tests. - The same tests pass on pydantic-ai, Microsoft Agent Framework and LangGraph.
- The docs explain how to write, run and skip tests.
- 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