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

Aperta
#60 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
docker, go, json, yaml

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
Python
Stelle
7
Fork
5
Merge medio
3h 39m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di orka-agents/agentkit

Tutte le issue di orka-agents/agentkit

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.