Notebooks
M
Meta Llama
Langgraph Tool Calling Agent

Langgraph Tool Calling Agent

llamaAIvllmmachine-learning3p-integrationsllama2LLMllama-cookbookPythonfinetuningpytorchlangchain

Open In Colab

[ ]

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:

  1. It allows us to define nodes for our assistant (which decides whether to call a tool) and our actions (tool calls).
  2. It allows us to define specific edges that connect these nodes (e.g., based upon whether a tool call is decided).
  3. It enables cycles, where we can call our assistant in a loop until a stopping condition.

Screenshot 2024-05-30 at 10.53.54 AM.png

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.

[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]
[ ]