Definition
Definition, what an agent is, with SubAgent for agents declared inside it and Problem for what a definition gets wrong.
A Definition records what an agent is: its models, instructions, tools, sub-agents and declared capabilities. It is checked the moment it is made. SubAgent declares an agent inside another, and Problem describes one way a definition is wrong.
Definition
What an agent is: its models, instructions, tools and capabilities.
It is checked when it’s created, so a mistake fails at the line that made it: data JSON can’t carry, credentials, and the definition schema. Nothing is sent until an agent uses it.
Example:
definition = ga.Definition(
description="Answers questions from the internal docs.",
model=ga.Model("openai", "gpt-4.1", temperature=0),
instructions="You research questions using the internal docs.",
tools=[search_docs],
)Parameters:
- model (
Model | BaseChatModel | Sequence[Model | BaseChatModel]) – The model, or models in fallback order: aModel, or a LangChain chat model, described by its provider, name and the settings that change its answers (never its keys or headers). - instructions (
Instruction | Sequence[Instruction] | None) – Text for a system prompt, or a list of text,SystemandDeveloperprompts, in order. - description (
str | None) – What the agent is for. - version (
str | None) – Your own label for this version of the agent. - framework (
Framework | None) – What it’s built with;Framework("custom")by default. - tools (
Iterable[Tool | Callable[..., Any] | BaseTool]) – Functions (marked withtoolor not),Tooland LangChain tools, each as the model sees it. - subagents (
Iterable[SubAgent]) – Agents declared inside this one, which sign as it. - middleware (
Iterable[Middleware]) – Middleware, in the order it runs. - mcp_servers (
Iterable[McpServer]) – MCP servers the agent uses. Tools loaded withlangchain-mcp-adaptersadd their own servers. - skills (
Iterable[Skill]) – Skills the agent has, each by its files’ CID. - memory (
Iterable[Memory]) – Memory it loads into its prompt: instructions it can’t change, and memory it learns. - permissions (
Iterable[str]) – Permissions it declares. - guardrails (
Iterable[str]) – Guardrails it declares. - graph (
Graph | None) – Its graph of nodes and edges. - sources (
Iterable[Source]) – Source files to fingerprint. - extensions (
Mapping[str, Any] | None) – Framework-specific data, keyed by framework name. - exclude (
Iterable[str]) – JSON Pointers to fields to leave out, recorded underextensions.guardian.excluded.
Raises:
DefinitionInvalid– The definition breaks the schema;problemssays where and how.DefinitionContainsSecret– It holds what looks like a credential;problemssays where.ValueError– Anexcludepointer names nothing, a list item or a field that can’t be left out,extensionsuses the reservedguardiankey, or a LangChain chat model sends a setting no definition can record (named, never its value).TypeError– An argument isn’t of a type the definition can hold, such as a LangChain model wrapped bybind_tools(), or made withconfigurable_fields.
Functions:
- document – The definition as the proxy receives it, for an agent named
name.
Definition.document
document(name: str) -> dict[str, Any]The definition as the proxy receives it, for an agent named name.
Parameters:
- name (
str) – The agent’s name, as enrolled withviper agent add.
Returns:
dict[str, Any]– A new copy each call: JSON data with the schema’s field names.
Raises:
ValueError–nameisn’t a valid agent name.
SubAgent
An agent declared inside another, which signs as its parent.
It takes the same arguments as Definition, plus its name, and
needs a description: the parent uses it to decide when to delegate.
Without a framework of its own, it inherits its parent’s name (package
versions are recorded once, on the parent). Its exclude pointers are
relative to the sub-agent and recorded in its own extensions. Its tools
loaded with langchain-mcp-adapters add their servers to its own
mcp_servers, as for Definition.
Example:
critic = ga.SubAgent(
"critic",
description="Reviews drafts for unsupported claims.",
model=ga.Model("openai", "gpt-4.1-mini"),
instructions="You review drafts.",
)Raises:
ValueError– The name isn’t a valid agent name, or as forDefinition.DefinitionInvalid– As forDefinition.DefinitionContainsSecret– As forDefinition.TypeError– As forDefinition, ordescriptionisn’t text.
Attributes:
- name (
str) – The sub-agent’s name, as requests name it.
SubAgent.name
name: strThe sub-agent’s name, as requests name it.
Problem
One way a definition is wrong.
Attributes:
- path (
str) – A JSON Pointer to the offending value;""is the whole definition. A missing field (required) or one that isn’t allowed (additionalProperties) is named by its own path, so/framework/namefor a framework without a name. Map keys that are not field names read<key>. - rule (
str) – The rule broken, as the JSON Schema keyword that states it, such astype,required,patternoruniqueItems; orjsonValue,jsonKey,finiteorcycle(a container inside itself) for data JSON can’t carry, andnestingfor maps and lists nested deeper than the proxy reads (127 levels), ormaxSizefor a document too large to walk. A rule with no keyword keeps a short name of its own; treat any rule you don’t recognise as informational.secretmarks what looks like a credential. Rules of the agent-definition crate the schema can’t state aremaxLength(in UTF-8 bytes),maxDepthandmaxSubAgentsfor sub-agents,transportfor an MCP server field its transport doesn’t use,writablefor a memory field itswritabledoesn’t allow (a CID on memory the agent changes, a scope on memory it can’t),scopefor a namespace hash on a shared scope, andoneOffor a prompt without exactly one ofcontentandcontentCid,nodefor a graph edge joining a node the graph doesn’t list, andsafeIntegerfor an integer beyond ±(2^53 - 1). - kind (
str) – For asecret, what it looks like, such asAPI key,credential fieldorcredential in a URL; otherwise empty.