<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Jones-Gilardi</title>
    <description>The latest articles on DEV Community by David Jones-Gilardi (@sonic_dmg).</description>
    <link>https://dev.to/sonic_dmg</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F523363%2F60fcc713-933a-4e78-ba18-0f9583adf843.jpeg</url>
      <title>DEV Community: David Jones-Gilardi</title>
      <link>https://dev.to/sonic_dmg</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sonic_dmg"/>
    <language>en</language>
    <item>
      <title>Unlocking Local AI: How to Use Ollama with Agents</title>
      <dc:creator>David Jones-Gilardi</dc:creator>
      <pubDate>Thu, 13 Feb 2025 17:13:50 +0000</pubDate>
      <link>https://dev.to/datastax/unlocking-local-ai-how-to-use-ollama-with-agents-2hc7</link>
      <guid>https://dev.to/datastax/unlocking-local-ai-how-to-use-ollama-with-agents-2hc7</guid>
      <description>&lt;p&gt;By now, there’s a good chance you’ve heard about generative AI or agentic flows (If you’re not familiar with agents and how they work watch &lt;a href="https://www.youtube.com/watch?v=NuxsHifAQa4" rel="noopener noreferrer"&gt;this video&lt;/a&gt; to get up to speed). There’s plenty of information out there about building agents with providers like OpenAI or Anthropic. However, not everyone is comfortable with exposing their data to public model providers. We get a consistent drum of questions from folks wondering if there’s a more secure and cheaper way to run agents. &lt;a href="https://ollama.com/" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt; is the answer.&lt;/p&gt;

&lt;p&gt;If you've ever wondered how to run AI models securely on your own machine without sharing your data with external providers, well, here you go!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you’d rather watch this content, &lt;a href="https://www.youtube.com/watch?v=bZDk5sgMLsk&amp;amp;t=2s" rel="noopener noreferrer"&gt;here’s a video&lt;/a&gt; covering the same topic.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why use Ollama?
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://ollama.com/" rel="noopener noreferrer"&gt;Ollama&lt;/a&gt; enables you to run models locally, ensuring that your data remains private and secure. Not only that, it won’t cost you any tokens. With Ollama, you can confidently run models on your hardware, knowing that your data is safe.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Getting started with Ollama&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Step 1: Install the model
&lt;/h3&gt;

&lt;p&gt;If you haven’t used Ollama before, you’ll need to install it locally first. Download and install the version needed for your operating system. It takes about five minutes.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2iaipmn74p4yjnqi6pyy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2iaipmn74p4yjnqi6pyy.png" alt="Download and install Ollama" width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, navigate to the models section and select tools. It's crucial to choose models that support tool calling when you want to build an agent.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h4m19kuaoozfmuh3um2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F2h4m19kuaoozfmuh3um2.png" alt="Choose " width="800" height="485"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg88t8z6f2y12d26jn32n.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg88t8z6f2y12d26jn32n.png" alt="Choose " width="800" height="483"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For this post, we'll use &lt;a href="https://ollama.com/library/qwen2.5" rel="noopener noreferrer"&gt;Alibaba's Qwen 2.5 7 billion parameter model&lt;/a&gt;, which is a great choice for local tool calling and agent interactions. It's only a 4.7GB download (Llama 3.1 405b is 243GB!) and is suitable to run on most machines.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzsni3raiihk2954v9x7q.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzsni3raiihk2954v9x7q.png" alt="Copy the " width="800" height="500"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Copy the installation command and paste it into your terminal after installing Ollama. Once the download is complete, you're ready to start working with the model!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr2dl5t56pztvn1v1tpgq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fr2dl5t56pztvn1v1tpgq.png" alt="Execute " width="800" height="131"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Step 2: Setting up Langflow
&lt;/h3&gt;

&lt;p&gt;Next, we'll use &lt;a href="https://www.langflow.org/" rel="noopener noreferrer"&gt;Langflow&lt;/a&gt;, a visual IDE that enables you to build generative and agentic AI flows in a low-code or no-code environment. If you're not familiar with Langflow, check out &lt;a href="https://www.datastax.com/products/langflow?utm_medium=byline&amp;amp;utm_campaign=local-ai-using-ollama-with-agents&amp;amp;utm_source=devto" rel="noopener noreferrer"&gt;this link&lt;/a&gt; for more information.&lt;/p&gt;

&lt;p&gt;1. Install Langflow: Use “&lt;a href="https://github.com/langflow-ai/langflow?tab=readme-ov-file#-quickstart" rel="noopener noreferrer"&gt;uv pip install langflow&lt;/a&gt;” in your terminal to install Langflow locally.&lt;/p&gt;

&lt;p&gt;2. Create a new flow: Choose the “Simple Agent” template.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6j4tyh2wy5aaggs1ybiq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F6j4tyh2wy5aaggs1ybiq.png" alt="Choose the " width="800" height="415"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once opened, you’ll see a ready-made simple agentic flow complete with an agent (defaulting to OpenAI’s gpt-4o-mini LLM), both URL and calculator tools, and chat input and output components.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb29clbfwjsq02slom8o.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fqb29clbfwjsq02slom8o.png" alt="The Simple Agent flow defaults to using OpenAI's gpt-4o-mini" width="800" height="448"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Transitioning to Ollama
&lt;/h2&gt;

&lt;p&gt;Now, let's switch from OpenAI to Ollama:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. Select custom model -&lt;/strong&gt; In the model provider list, choose the custom option.&lt;/p&gt;

&lt;p&gt;Since our goal is to use Ollama and not OpenAI, click the “Model Provider” dropdown in the agent component and choose “Custom.”&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Add Ollama component:&lt;/strong&gt; Drag and drop the Ollama model into your flow and connect the “Language Model” nodes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Refresh the model list and choose qwen2.5 -&lt;/strong&gt; Make sure to refresh the model name dropdown to populate the available models. It's essential to have Ollama running locally for this setup to work.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;To use an Ollama model with your agent, it must support tool calling. In Langflow, enable the “Tool Model Enabled” radio button to filter models that have this capability. Once enabled, select **qwen2.5&lt;/em&gt;* for your operations.*&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Running your query&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Now, let's run a query using the Ollama model. Open the “Playground” and try typing in an example like “convert 200 USD to INR”. If everything is wired up correctly, the model will attempt to answer your query using the tools at its disposal.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmkakblgict6do1hm085.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fjmkakblgict6do1hm085.png" alt="Open the Playground using the top right hand corner menu" width="800" height="557"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryfeuq4iasscdw961c95.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fryfeuq4iasscdw961c95.png" alt="Try an example like " width="800" height="402"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Keep in mind that local models may take longer to process, especially larger ones. However, Qwen 2.5 is optimized for smaller machines, making it pretty solid for local use.&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Experimenting with inputs
&lt;/h3&gt;

&lt;p&gt;When working with smaller local models, you may need to experiment with your inputs. Sometimes, you might have to explicitly instruct the model to do something, like use the web to find the latest exchange rates. Adjusting the model's temperature settings can also help; starting with a conservative value (like 0.10) is a good practice, but feel free to increase it for more creative responses.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu73y96bijss56j08m3f3.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu73y96bijss56j08m3f3.png" alt="The smaller model didn't quite get it right the first time. Give it a nudge with an extra instruction like " width="800" height="857"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Notice how the agent updated its approach when I told it to “use the web to get the latest exchange rates” and gave the correct answer. This time, it used the URL tool to grab the latest exchange rate from the web as compared to relying solely on the knowledge it was trained on.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1f4emdciml6nic937br0.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F1f4emdciml6nic937br0.png" alt="Now we can see it properly used the URL tool to fetch exchange rates" width="800" height="897"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Finally, once your Ollama agent is set up within Langflow, you can integrate it into your applications via API, allowing you to enable your apps with full agentic capability.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu27huh5jd0gu5zup68b9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu27huh5jd0gu5zup68b9.png" alt="Use the API option to connect AI flows to your applications" width="800" height="234"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all it takes to harness the power of local models securely with Ollama and your agents. If you have any questions or need further assistance, feel free to reach out on our &lt;a href="https://discord.gg/datastax" rel="noopener noreferrer"&gt;Discord&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Happy coding!&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
