Ch.07 - Make dynamic tool selector section more clear and meaningful #5

Open
opened 2026-02-16 07:16:28 -05:00 by yindo · 0 comments
Owner

Originally created by @JamesCHub on GitHub (Jul 8, 2025).

The book is extremely useful and well-written.

In the section in Chapter 6 entitled "Dealing with Many Tools", we don't add any new tools, and don't limit the retriever, so the point of the section is a bit lost.

But if we simply modify the retriever definition to:
tools_retriever = InMemoryVectorStore.from_documents([Document(tool.description, metadata={"name":tool.name}) for tool in ourTools], embeddingsModel).as_retriever(search_kwargs={"k": 1, "fetch_k": 2})

We'll force the agent to choose the best single tool to answer the prompt.

We can then cycle through three prompts:

  1. "When was Calvin Coolidge born?" (only search will be selected)
  2. "2+2=" (only calculator will be selected)
  3. "How old was the 30th president of the US when he died?" (search will be selected)
Originally created by @JamesCHub on GitHub (Jul 8, 2025). The book is extremely useful and well-written. In the section in Chapter 6 entitled "Dealing with Many Tools", we don't add any new tools, and don't limit the retriever, so the point of the section is a bit lost. But if we simply modify the retriever definition to: `tools_retriever = InMemoryVectorStore.from_documents([Document(tool.description, metadata={"name":tool.name}) for tool in ourTools], embeddingsModel).as_retriever(search_kwargs={"k": 1, "fetch_k": 2})` We'll force the agent to choose the best single tool to answer the prompt. We can then cycle through three prompts: 1. "When was Calvin Coolidge born?" (only search will be selected) 2. "2+2=" (only calculator will be selected) 3. "How old was the 30th president of the US when he died?" (search will be selected)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/learning-langchain#5