Перейти к содержимому

L9 Build an OpenRouter Agent That Calls Tools Until It Finds the Answer | Preventing Hallucinating

Richard Young

0:00 / 0:00

L9 Build an OpenRouter Agent That Calls Tools Until It Finds the Answer | Preventing Hallucinating

260 просмотров · 12 дн. назад
Richard Young
232 подписчика
260 просмотров · 12 дн. назад
0:00 Introduction & Loop Concept 0:26 Setup: Tools and Reference Data 1:07 Model & Observation Trick 2:00 Parser and Components Overview 3:00 Running Questions & Trap Example 4:30 Trace for Debugging Agent Calls In this OpenRouter tutorial, you'll learn how to build a tool-calling agent loop using Ollama and OpenRouter. The video walks through creating a ReAct-style loop where an LLM repeatedly calls Python functions (tools) to answer complex questions, with a focus on medical data examples like metformin and EGFR thresholds. You'll see how to set up a reasoning model (Qwen 3 8B), define lookup and reference tools, parse model output for action calls, and implement a loop that stops after a maximum number of iterations or when an observation is generated. The tutorial also covers debugging with a trace, adding multiple tools, and avoiding hallucination by halting generation on 'Observation'. The workflow is demonstrated in a Colab notebook, with tips on switching to an A100 runtime for faster performance. By the end, you'll understand how to extend LLMs beyond simple RAG by enabling them to query databases, apply rules, and chain tool calls for reliable, verifiable answers. Key takeaways: Use a loop to repeatedly call tools until the goal is reached or a max iteration limit is hit. Tools are ordinary Python functions that can query databases, run SQL, or perform any action. The model stops generating when it outputs 'Observation', preventing hallucination of answers. A trace provides a step-by-step record of agent thoughts and tool calls for debugging. Add multiple tools (e.g., lookup, database write) to handle complex, multi-step questions. Reasoning models like Qwen 3 can output thinking blocks, but the loop still relies on explicit action parsing. Set a maximum iteration count (e.g., 100) to prevent infinite loops in tool-calling agents. Key terms: ReAct loop: A pattern where an LLM reasons (thinks) and acts (calls tools) in a cycle until a goal is achieved. Tool calling: The ability of an LLM to invoke external functions (e.g., lookup, calculator) to gather information or perform actions. Observation: A keyword that, when output by the model, halts generation and signals the loop to inject real tool results. Qwen 3 8B: An 8-billion parameter reasoning model from Alibaba that can output thinking blocks and is used in the tutorial. OpenRouter: A service that provides access to various LLMs via a unified API, used here as an alternative to local Ollama. Ollama: A tool for running large language models locally, used in the tutorial to serve Qwen 3. EGFR: Estimated glomerular filtration rate, a measure of kidney function used in the medical example to assess metformin safety. Metformin: A common diabetes medication; the tutorial uses it to demonstrate tool lookups for drug safety guidelines. #OpenrouterTutorial #OpenrouterFreeModels #Openrouter Questions? Post them in the comments. I read them. More from me: https://deepneuro.ai/richard | https://young.faculty.unlv.edu Dr. Richard Young Lee Business School, University of Nevada, Las Vegas (UNLV) UNLV Graduate College | Graduate education