feat: publish a JSON schema for the Agentkitfile for editor autocomplete

Open
#60 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
5/5
Estimated time
Over a week
Newbie friendliness
35/100
Issue type
Feature
Clarity
Clearly specified
Activity status
Active
Tech stack
docker, go, json, yaml

Research direction

Start by reading the Go config types in pkg/agentkit/config/specs.go, tool.go, and source.go, then compare the generator example at dalec's cmd/gen-jsonschema/main.go. Generate docs/agentkitfile.schema.json from the YAML tags, add the documented special cases, and cover the listed fixtures and invalid examples. The issue's done criteria include a CI freshness check, editor behavior, and the --call feature only after #58 lands.

Written by the indexing model from the issue text.

Description

area/build enhancement help wanted

Problem

The Agentkitfile is strict: an unknown or misspelled field fails the build. But editors give no help while you write one. There's no autocomplete, no hover help and no red underline on a typo, so:

  • every typo costs a full build attempt;
  • you learn field names by reading docs/agentkitfile.md.

Most YAML editors can do all of this if they're given a JSON schema, a file that describes which fields are allowed. AgentKit doesn't publish one. dalec generates one from its Go types (cmd/gen-jsonschema/main.go, docs/spec.schema.json) and also serves it through docker buildx build --call dalec.schema.

What

  1. Generate a JSON schema for the Agentkitfile from the Go config types and check it in as docs/agentkitfile.schema.json.
  2. Keep it current: CI fails if someone changes the config types without regenerating it.
  3. Let editors use it with one comment in the file:
    #syntax=ghcr.io/orka-agents/agentkit/agentkit:latest
    # yaml-language-server: $schema=https://raw.githubusercontent.com/orka-agents/agentkit/main/docs/agentkitfile.schema.json
    apiVersion: v1alpha1
    kind: Agent
    
    • Order matters. The schema comment must come after the #syntax line. BuildKit stops looking for #syntax at the first comment that isn't a directive (see DirectiveParser.ParseLine in BuildKit's frontend/dockerfile/parser/directives.go).
    • Matching versions. For a pinned frontend version, use the same tag in the schema URL, for example .../v0.5.0/docs/agentkitfile.schema.json, so the editor matches the frontend.
  4. Serve it from the frontend: docker buildx build --call agentkit.schema -f agentkitfile.yaml . prints the schema for the exact frontend version in #syntax, the same way dalec's --call dalec.schema does. This builds on the --call support in #58. If #58 isn't merged yet, leave this part for a follow-up.

The schema is there to help with editing. The Go checks in validate.go remain the source of truth, so don't try to express every rule in the schema.

Out of scope
  • A VS Code extension.
  • Registering the schema with SchemaStore so editors pick it up without the comment. That's a good follow-up once the file is stable.

Why

  • Typos show up while typing, not after a build.
  • Autocomplete and hover help make the format easy to learn.
  • It's cheap: the schema is generated from code that already exists.

How

Where things are
File What it does
pkg/agentkit/config/specs.go, tool.go, source.go The Agentkitfile types. They use yaml tags (no json tags) and have doc comments.
pkg/agentkit/config/load.go Strict loader: unknown fields fail. The schema should match this with additionalProperties: false.
pkg/agentkit/config/source.go Source (used by instructions) accepts a plain string or an {inline} / {file} mapping. It needs a hand-written schema.
pkg/agentkit/runtimes Runtime names and aliases, for the runtime enum.
dalec cmd/gen-jsonschema/main.go Example generator using github.com/invopop/jsonschema.
Steps
  1. Add a generator, for example cmd/gen-schema/main.go, using github.com/invopop/jsonschema.
    • Field names must come from the yaml tags. invopop reads json tags by default, so set its option for another tag name. Check the exact option in the version you pick.
    • Use Go doc comments as field descriptions (AddGoComments, as dalec does) so editors show hover help.
    • Set additionalProperties: false so unknown fields are flagged, matching the strict loader.
  2. Hand-write the special cases with a JSONSchema() method on the type. invopop picks it up automatically.
    • instructions (Source): a string, or an object with inline or file.
    • Fields with fixed values, using enum:
      • apiVersion: v1alpha1
      • kind: Agent
      • model.provider: openai-compatible
      • runtime: names and aliases from pkg/agentkit/runtimes
      • auth.type
      • context.providers[].type
      • tools[].transport
    • Fields that hold env var names (apiKeyEnv, urlEnv, tokenEnv, env[].name and so on): pattern: "^[A-Z0-9_]+$", the same rule as isEnvVarName in validate.go.
  3. Add a make target, for example make schema, that writes docs/agentkitfile.schema.json.
  4. Add a CI check: regenerate the file and fail on git diff --exit-code docs/agentkitfile.schema.json.
  5. Add --call agentkit.schema once #58 has landed.
    • Embed the file in the frontend (//go:embed) and return it as result.json / result.txt metadata, as dalec's handleJSONSchema does in frontend/client.go.
    • BuildKit's dockerui.HandleSubrequest rejects unknown calls unless AllowOther: true, so either handle this call before it or set that option.
Tests
  • Every example file passes the schema: each test/agentkitfile-*.yaml fixture, and each YAML example in README.md and docs/, if they're easy to extract. Use a Go JSON Schema validator such as github.com/santhosh-tekuri/jsonschema. This catches the schema and the loader drifting apart.
  • Mistakes fail it: a misspelled field, a wrong kind, and a lowercase env name.
  • Manual check: in VS Code with the Red Hat YAML extension, a file with the comment shows autocomplete, hover help and an error on a typo.

Run:

go test ./...
make lint
Docs
  • docs/agentkitfile.md: add an "Editor support" section with:
    • the comment line;
    • the note that it goes after #syntax;
    • the versioned URL;
    • how to set it up in VS Code;
    • the --call agentkit.schema command, once available.
  • README.md: add the comment line to the quick-start example.

Done when

  • docs/agentkitfile.schema.json is generated from the Go types, and CI fails when it's out of date.
  • All fixtures and examples pass the schema, and the sample mistakes fail it.
  • With the comment line, VS Code shows autocomplete and flags typos, and #syntax still works.
  • --call agentkit.schema prints the schema, once #58 has landed.
Dominant language
Python
Stars
7
Forks
5
Avg merge
3h 39m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from orka-agents/agentkit

All issues in orka-agents/agentkit

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.