"This notebook goes through how to create your own custom agent.\n",
"\n",
"In this example, we will use OpenAI Function Calling to create this agent.\n",
"In this example, we will use OpenAI Tool Calling to create this agent.\n",
"**This is generally the most reliable way to create agents.**\n",
"\n",
"We will first create it WITHOUT memory, but we will then show how to add memory in.\n",
@ -61,10 +61,21 @@
},
{
"cell_type": "code",
"execution_count": 5,
"id": "fbe32b5f",
"execution_count": 2,
"id": "490bab35-adbb-4b45-8d0d-232414121e97",
"metadata": {},
"outputs": [],
"outputs": [
{
"data": {
"text/plain": [
"3"
]
},
"execution_count": 2,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from langchain.agents import tool\n",
"\n",
@ -75,6 +86,16 @@
" return len(word)\n",
"\n",
"\n",
"get_word_length.invoke(\"abc\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c9821fb3-4449-49a0-a708-88a18d39e068",
"metadata": {},
"outputs": [],
"source": [
"tools = [get_word_length]"
]
},
@ -91,7 +112,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 4,
"id": "aa4b50ea",
"metadata": {},
"outputs": [],
@ -116,22 +137,24 @@
"metadata": {},
"source": [
"## Bind tools to LLM\n",
"\n",
"How does the agent know what tools it can use?\n",
"In this case we're relying on OpenAI function calling LLMs, which take functions as a separate argument and have been specifically trained to know when to invoke those functions.\n",
"\n",
"To pass in our tools to the agent, we just need to format them to the [OpenAI function format](https://openai.com/blog/function-calling-and-other-api-updates) and pass them to our model. (By `bind`-ing the functions, we're making sure that they're passed in each time the model is invoked.)"
"In this case we're relying on OpenAI tool calling LLMs, which take tools as a separate argument and have been specifically trained to know when to invoke those tools.\n",
"\n",
"To pass in our tools to the agent, we just need to format them to the [OpenAI tool format](https://platform.openai.com/docs/api-reference/chat/create) and pass them to our model. (By `bind`-ing the functions, we're making sure that they're passed in each time the model is invoked.)"