Skip to content
Zever
Home

Build an agent app

Wire an agent loop, RAG grounding, and an MCP server into a working support assistant.

2 min readEdit on GitHub

You will build a support assistant that answers from your docs (RAG), calls tools in an agent loop, and exposes your schema to coding agents over MCP. You need an AI_API_KEY for generation and embeddings; retrieval and MCP run locally. Run commands from the repository root.

Every agent app starts from the container. Agent() builds a tool-calling loop over the shared AI backend, and RAG() builds a retrieval engine over AI plus VectorStore:

Terminal window
AI_ADAPTER=openai AI_API_KEY=sk-... zever doctor --json | head -5

Ingest documents once, then retrieve top-K context per question. Chunking, batch embedding, and upserting are one call:

Terminal window
# Conceptually: engine.Ingest(ctx, docs) then engine.Answer(ctx, query, 5)
# See core/rag/rag.go and the RAG section of the AI guide.

Register domain tools, then run. Unknown tools fail closed, and handler errors return to the model as tool turns so it can self-correct:

Terminal window
# Conceptually: agent.New(client, agent.Options{Model: "gpt-4o", Tools: tools})
# then loop.Run(ctx, messages). See core/agent/agent.go.

Long runs stream deltas, tool calls, and results as events. Independent tool calls in one step run concurrently with MaxParallel, and results keep their order:

Terminal window
# Conceptually: loop.RunStream(ctx, messages) then range over events.
# See core/agent/stream.go.

Compile the schema with the mcp backend. It writes one tool manifest per module (generated/mcp/<module>/mcp.json), a merged generated/mcp/mcp.json, and a runnable stdio server with handler stubs you fill in (generated/mcp/<module>/mcpserver/main.go):

Terminal window
zever compile schema/app.zen --backend=mcp --out ./generated
go run ./generated/mcp/<module>/mcpserver

Separately, go run ./tools/zever-mcp starts a stdio server that gives coding agents the compiler itself as tools (zever_compile, zever_schema, zever_explain).

Pin quality with a dataset and scorers before you ship prompt changes:

Terminal window
# Conceptually: eval.RunSuite(ctx, run, cases, eval.ContainsScorer).
# See core/eval/eval.go.
  • container.Agent() and container.RAG() lazy accessors over shared backends
  • core/agent loops: run, stream, parallel fan-out, sub-agent tools
  • core/rag ingest, retrieve, hybrid retrieval, grounded answers
  • dsl/backend/mcp manifests plus a generated stdio server, and tools/zever-mcp for compiler tools
  • core/eval datasets and scorers
Agent() fails with an auth error

Cause: no API key, and the loop needs a real backend. Fix: set AI_API_KEY. Retrieval-only paths work with any embedder.

Hybrid retrieval returns nothing

Cause: hybrid engines index chunks into the keyword backend on ingest. Fix: re-ingest after switching from rag.New to rag.NewHybrid.