Creating Local AI Agents with Foundry Local and Qwen
Companion skill for Lesson 17 – Creating Local AI Agents.
Use it to help a learner build an agent that reasons, calls tools, and searches
documentation entirely on their own machine — no cloud inference. Ground every
recommendation in the lesson content and the runnable notebook.
Triggers
Activate this skill when a learner wants to:
- Run an agent fully on-device for privacy, cost, or offline reasons.
- Serve a model locally with Foundry Local and connect via the OpenAI-compatible endpoint.
- Use a Qwen function-calling model to drive reliable local tool calls.
- Add local RAG (Chroma) or a local MCP server.
- Design a hybrid local/cloud routing strategy.
Core mental model
An SLM trades breadth for privacy, cost, and offline operation. The winning
strategy: let the SLM orchestrate and let tools do the heavy lifting. The
model does not need to know the codebase — it needs to know when to call
read_file and search_docs. That plays to an SLM's strength (bounded decisions
like tool selection) and away from its weakness (broad knowledge, long multi-hop
reasoning).
Why these specific pieces
- Foundry Local exposes an OpenAI-compatible HTTP endpoint, so cloud agent code transfers by changing only
base_url(and using a local placeholder API key). It also auto-selects the best build (CPU/GPU/NPU) for the machine. - Qwen models are trained for function calling and emit well-formed tool calls consistently — this is what turns a local chat model into a local agent.
- Chroma runs in-process and stores vectors on disk, so the whole RAG pipeline (embed → store → retrieve → reason) stays local.
- MCP is a transport, not a cloud service: an MCP server can run locally over
stdio.
Setup essentials
foundry model run qwen2.5-7b
foundry service status
from foundry_local_sdk import Configuration, FoundryLocalManager # foundry-local-sdk 2.x
from openai import OpenAI
FoundryLocalManager.initialize(Configuration(app_name="ai_agents_for_beginners"))
manager = FoundryLocalManager.instance
model = manager.catalog.get_model("qwen2.5-7b")
if not model.is_cached:
model.download()
model.load()
manager.start_web_service()
client = OpenAI(base_url=manager.urls[0].rstrip("/") + "/v1", api_key="not-required") # local placeholder
~8 GB RAM is a realistic minimum; a GPU/NPU helps but is not required.
Key patterns to reproduce
Point the learner at the notebook