Skip to main content

馃憪 Create a basic tool-calling agent

Let's start by creating a basic tool-calling agent using the create_tool_calling_agent constructor in LangChain.

Fill in any <CODE_BLOCK_N> placeholders and run the cells under the Step 7: Create a basic tool-calling agent section in the notebook to create a basic tool-calling agent.

tip

Skip over the 馃Ω CoT prompting section for now. Come back to it if time permits.

The answers for code blocks in this section are as follows:

CODE_BLOCK_18

Answer
f"""Answer the following questions as best you can.
You can answer directly if the user is greeting you or similar.
Otherwise, you have access to the following tools:

{render_text_description(tools)}
"""

CODE_BLOCK_19

Answer
prompt = ChatPromptTemplate.from_messages(
[
("system", system_message),
("human", "{input}"),
MessagesPlaceholder("agent_scratchpad"),
]
)

agent = create_tool_calling_agent(llm, tools, prompt)

agent_executor = AgentExecutor(
agent=agent, tools=tools, verbose=True, handle_parsing_errors=True
)