Build Tools for an Agent
An agent retrieves context from Zep through tools. The tool set decides which retrievals the agent can make, and the tool descriptions decide when the agent makes them. This page shows the tools of the reference agent. Read Build an Agent with Zep first for the agent loop.
Choose tools for the task
Select tools from what the agent must do. The ontology tells you what the graph contains. The task tells you which retrievals the agent repeats.
- Start with the functional tools. They cover search, complete lists, graph traversal, and full details.
- Run the agent on your gold questions, and read the tool calls.
- Add a domain-specific tool when the agent often makes the same sequence of generic calls.
- Add a domain-specific tool when a business term maps to a fixed retrieval recipe.
The reference agent has four functional tools and two domain-specific tools:
In the reference dataset, one question asks which members of Reliability Engineering work on the Aster 410. With functional tools, the agent needs a team lookup, a product lookup, two neighbor calls, and an intersection. get_employees does the same retrieval in one call.
Pin and expose parameters
The application pins the parameters that control identity, security, cost, and result quality. The model controls only the arguments that the task changes.
The pinned and exposed parameters for each tool in the reference agent:
When a request sets a limit, the list API returns at most 50 nodes in a page. The tool requests one extra node to find out if the list is complete.
Functional tools
The functional tools map to the Zep graph API. The examples use Pydantic AI. The same structure works in other agent frameworks. The examples are shorter than the reference agent code. Helper functions such as format_list format the results, as the result shape section describes.
search_context
search_context searches one scope with the cross_encoder reranker. The model can add entity type, edge type, and episode metadata filters. In the edge and node scopes, the model can add results from the neighborhood of known nodes. These breadth-first search (BFS) results are merged with the other search results. They do not restrict the search.
list_nodes
list_nodes returns every node of one entity type, up to a limit. Use a list tool when the question needs a complete set. A search returns only the most relevant items.
get_neighborhood
get_neighborhood follows the edges of a known node. The direction argument selects the edge direction: out for edges from the node, in for edges to the node, or both.
get_details
get_details returns the full attributes of a node or the full text of an episode. Search results are short. The agent calls get_details when a result is relevant but does not contain enough text to answer from.
Domain-specific tools
A domain-specific tool maps a business task to a fixed retrieval recipe. The application pins the labels, the edge types, and the call sequence. The model gives arguments in domain terms.
get_employees
get_employees finds the employees on a team, on a product, or on both. The tool returns the title, the team, and the manager of each employee.
search_products
search_products returns the products with their category, lifecycle status, and each regulatory filing. The tool description includes the domain rule for clearance, so the agent reads each filing status.
The full code is in agent_with_zep/tools.py in the reference agent.
Write tool descriptions
The model selects a tool from its name, its description, and its parameter types. A tool description contains:
- What the tool returns.
- When to use the tool, with an example from the domain.
- If the result is a ranked sample or a complete set.
- The rules for each argument that the model can get wrong, such as a filter value or a handle prefix.
Compare two descriptions for the same tool:
Use enum types from the ontology for entity type and edge type arguments. The model then cannot send a label that does not exist in the graph.
Result shape
Return compact text. Each line is one item, with only the fields that the agent needs.
The reference agent applies these rules to each result:
- Handles. Each node, edge, and episode gets a short handle (
n1,e1,p1) in place of its UUID. The model passes handles to the tools that take a node or an episode. The application resolves each handle to its UUID. - Deduplication. The same UUID gets the same handle in every result of a run. An item that the agent already has is marked
seen. - Completeness. The first line says
ranked sample,complete, ortruncated at N. A list tool requests one item more than the limit to find out if more items match. - Size. Each result is limited to 4,000 characters.
- Budget. A tool that is called after the budget is spent returns a notice. A repeated call with the same arguments also returns a notice.
- Errors. A tool returns invalid arguments and Zep API errors to the model as text. The model can then change the arguments or use a different tool. An error does not stop the run. A tool that rejects its arguments does not use the budget.
Use the tools with an agent framework
The reference agent registers the tools in one Pydantic AI FunctionToolset. The agent gets the toolset, the system prompt, and a function that hides the retrieval tools until the model submits a plan.
The framework integration pages show how to connect Zep to each framework. Use the same tool contracts in each framework. Pin the graph and the limits in the application, and expose only the task arguments to the model.