Langgraph Tool Calling Agent
LangGraph Tool Calling Agent with Llama3
LLM-powered agents combine planning, memory, and tool-use (see here, here).
LangGraph is a library that can be used to build agents:
- It allows us to define
nodesfor our assistant (which decides whether to call a tool) and our actions (tool calls). - It allows us to define specific
edgesthat connect these nodes (e.g., based upon whether a tool call is decided). - It enables
cycles, where we can call our assistant in a loop until a stopping condition.
We'll augment a tool-calling version of Llama 3 with various multi-model capabilities using an agent.
Environment
We'll use Tavily for web search.
We'll use Replicate, which offers free to try API key and for various multi-modal capabilities.
We can review LangChain LLM integrations that support tool calling here.
Groq is included. Here is a notebook by Groq on function calling with Llama 3 and LangChain.
Optionally, add tracing:
Define tools
These are the same tools that we used in the tool-calling-agent notebook.
State
This list of messages is passed to each node of our agent.
This will serve as short-term memory that persists during the lifetime of our agent.
See this overview of LangGraph for more detail.
Assistant
This is Llama 3, with tool-calling, using Groq.
We bind the available tools to Llama 3.
And we further specify the available tools in our assistant prompt.
Graph
Here, we lay out the graph.
We can visualize it.
Test
Now, we can test each tool!
See the traces to audit specifically what is happening.