feat(build): run agent tests during the image build
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 25/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Ambito
- build-system, devtools
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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.
- Lingua principale
- Python
- Stelle
- 7
- Fork
- 5
- Merge medio
- 3h 39m
- PR unite (30g)
- 1
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di orka-agents/agentkit
-
fix(pydantic-ai): CI fails with newest pydantic-ai (unexpected 'history' argument)Forse già presa @gambtho l’ha presa 30 giorni fa. Aperta
Difficoltà 3/5 1-2 giorni Idoneità per principianti 35/100
orka-agents/agentkit#77 ·
-
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
orka-agents/agentkit#76 · 3 commenti ·
-
area/build area/orka area/runtime blocked enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
orka-agents/agentkit#69 ·
-
area/build area/orka area/runtime enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
orka-agents/agentkit#68 ·
-
area/build enhancement testing
Difficoltà 5/5 Più di una settimana Idoneità per principianti 42/100
orka-agents/agentkit#65 ·
Tutte le issue di orka-agents/agentkit
Issue simili
-
【文档错误】创建镜像空间步骤中的截图标注与文字描述不一致Apertaenhancement
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 62/100
DaoCloud/DaoCloud-docs#7839 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
sav-oss-org/ptusa_main#1610 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 85/100
I maintainer di solito rispondono entro 1 giorno
-
bug status/accepted type/bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
microsoft/apm#4925 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
sagemathinc/sagebrush#1701 ·
I maintainer di solito rispondono entro 1 giorno