Meta-agent that builds agents
Goal
Describe a job in one sentence and have the platform build the agent for it. A
meta-agent searches the platform's own catalogue for reusable tools (and agents,
collections, graphs), then calls create_agent to register a working agent wired to
the tools it found - no hand-assembly.
This recipe shows the platform's internal semantic search (over its own tools and entities) and dynamic agent creation from inside an agent. The operator's job is to activate the internal search subsystem, create the meta-agent once, and start a session; the meta-agent does the discovery and the creation at runtime. Each setup step is shown two ways: first in the console, then via the CLI.
Ingredients
- An LLM provider.
- An embedding provider and a semantic search provider (the internal catalogue
is embedded for
search_toolsto be real). - The
searchtoolset (search_tools, and optionallysearch_agents,search_collections,search_graphs- semantic search over the platform's own_internal_*catalogue). system__create_agentso the meta-agent can register what it designs.- A local workspace for the meta-agent session.
- To drive the CLI path, point
primectlat your instance once; see the one-time Connecting the CLI block in the RAG recipe.
Walkthrough
1. Activate the internal search subsystem
search_tools searches an embedded catalogue of the platform's own tools, so the
subsystem needs an embedder and a search provider, then a one-time bootstrap that
indexes the catalogue. Create the providers the same way the RAG recipe does
(Providers > Embedding and Providers > Semantic Search, or
primectl create -f embedder.yaml / ssp.yaml), then point the subsystem at them.
In the console:
- Go to Subsystems > Internal Collections, set the Embedding provider, Embedding model, and Search provider in the config form, and save.
- Click Bootstrap and watch the status pill: it runs in the background and turns
to
succeededwhen the catalogue is indexed.
Via the CLI (the internal-collections subsystem is a singleton, so it is configured and
bootstrapped with primectl raw, the explicit escape hatch):
primectl raw PUT /v1/internal_collections/config -f ic_config.yaml
primectl raw POST /v1/internal_collections/bootstrap
primectl raw GET /v1/internal_collections/bootstrap/status # poll until "succeeded"
where ic_config.yaml is:
embedding_provider_id: <embedder>
embedding_model: <embed-model>
search_provider_id: <ssp>
2. Create the meta-agent
It binds search_tools plus create_agent. The system prompt makes it discover first,
then create once.
In the console:
- Go to Compute > Agents and click New agent.
- On the Basic tab set ID to
meta-builder, add a Description, and pick the LLM provider and Model. - On the Tools tab check
search__search_toolsandsystem__create_agent. - On the Advanced tab paste the system prompt (below). Click Create.
Via the CLI:
primectl create -f meta-builder.yaml
where meta-builder.yaml is:
kind: agent
spec:
id: meta-builder
description: Builds new agents from a use case by discovering existing tools.
model:
provider_id: <llm>
model_name: <model>
tools:
- search__search_tools
- system__create_agent
max_tool_turns: 8
system_prompt:
- >-
You build new agents. Given a use case: (1) call search_tools to find relevant
platform tools (it returns scoped ids like misc__get_datetime); (2) call
create_agent ONCE to create a new agent that solves the use case. The
create_agent arguments must include: id (a short slug), description, model
{provider_id, model_name}, tools (the scoped tool ids you found), and
system_prompt (a list with one instruction string). Report the new agent id.
3. Run the meta-agent with a use case
Start a session bound to the meta-agent and pass the use case as the instruction.
In the console:
- Click New session, set the Binding to
agent, pickmeta-builder, choose a Workspace, and type the use case into Initial instructions. - Click Create and watch the transcript: the agent calls
search_tools, thencreate_agent. The new agent it builds appears on the Agents page.
Via the CLI:
primectl session run <workspace-id> --agent meta-builder \
-i "Use case: build an agent that returns the current date and time on request."
A few things worth knowing:
search_toolsreturns scoped ids (<toolset>__<tool>) - exactly the shape an agent'stoolslist needs, so the meta-agent can paste them straight intocreate_agent. Internal search is also how it finds existing agents (search_agents), collections, and graphs to reuse instead of rebuilding.create_agentids are immutable. If the meta-agent picks an id that exists, the call fails - have it choose a fresh slug.- Yielding tools can't come over MCP. When the meta-agent discovers an external
MCP server, register it as a toolset (the
mcptoolset-provider kind) beforecreate_agent, since the new agent'stoolsmust reference already-registered ids; only the MCP server's request/response tools are usable. - Want parallel discovery? Wrap the four searches (
search_tools/search_agents/search_collections/search_graphs) as afan_out(tee) in a graph that fans into a planner, then a builder node. On a single-concurrency LLM the searches serialize either way, so a single agent (above) is the simpler equivalent.
Testing
"Use case: build an agent that returns the current date and time on request."
Expected outcome (verified):
- The meta-agent calls
search_tools, finds the datetime tool (misc__get_datetime), and callscreate_agent. Watch the transcript on the Sessions page, or readended: completedfromsession run. - A new agent appears on the Agents page - for example
datetime-agentwithtools: ["misc__get_datetime"]- that you can immediately run. Confirm withprimectl get agent datetime-agent -o yaml. - The freshly built agent is immediately runnable: start a session bound to it
(New session or
primectl session run <workspace-id> --agent datetime-agent -i "what time is it") and watch it reach a clean terminal.
Try other one-line use cases ("an agent that searches the web and summarizes", "an agent that answers from the kb collection") and watch it wire up the matching tools each time.