<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by John Boos on Medium]]></title>
        <description><![CDATA[Stories by John Boos on Medium]]></description>
        <link>https://medium.com/@j.robert.boos?source=rss-49efbda44c8b------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by John Boos on Medium</title>
            <link>https://medium.com/@j.robert.boos?source=rss-49efbda44c8b------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 20:43:41 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@j.robert.boos/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[External Providers in llama-stack]]></title>
            <link>https://medium.com/@j.robert.boos/external-providers-in-llama-stack-17d1af4365aa?source=rss-49efbda44c8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/17d1af4365aa</guid>
            <category><![CDATA[llama-stack]]></category>
            <dc:creator><![CDATA[John Boos]]></dc:creator>
            <pubDate>Wed, 04 Jun 2025 15:17:08 GMT</pubDate>
            <atom:updated>2025-06-04T15:17:08.879Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post covers how to create your own custom external providers in llama-stack. External providers are a fantastic way to add new functionality to your llama-stack!</em></p><h3>Required Dependencies</h3><p>Run the following line to install all the required dependencies.</p><pre>pip install -r https://raw.githubusercontent.com/jrobertboos/learn-external-providers/refs/heads/main/requirements.txt</pre><h3>Create the External Provider Package</h3><p>In order to create an external provider for llama-stack a package the provider must be made into a package. According to the <a href="https://llama-stack.readthedocs.io/en/latest/providers/external.html">documentation</a> llama-stack external providers should prefix with llama-stack-provider.</p><p>In this tutorial we will be creating a Safety external provider, it will be called grumpy-guard. Below is the package directory structure:</p><pre>llama-stack-provider-grumpy-guard/<br>├─ pyproject.toml<br>├─ README.md<br>├─ src/<br>│  ├─ llama_stack_provider_grumpy_guard/<br>│  │  ├─ __init__.py<br>│  │  ├─ config.py<br>│  │  ├─ custom_guard.py</pre><p>At the top of your package directory is pyproject.toml, this controls your package settings. The pyproject.toml for grumpy-guard is:</p><pre>[project]<br>name = &quot;llama-stack-provider-grumpy-guard&quot;<br>version = &quot;0.1.0&quot;<br>description = &quot;Grumpy Guard safety provider for llama stack&quot;<br>readme = &quot;README.md&quot;<br>requires-python = &quot;&gt;=3.10&quot;<br>dependencies = [&quot;llama-stack&quot;, &quot;pydantic&quot;]</pre><p>Within the package directory will be your packages source code. For grumpy-guard the source code is in src/llama_stack_provider_grumpy_guard/ . grumpy-guard has 3 files that contain the code, __init__.py , config.py , and grumpy_guard.py .</p><h4>__init__.py</h4><p>In __init__.py we define get_provider_impl this is a required method when creating a custom external provider. You can also see that we have GrumpyGuardConfig, this is another required component that we will discuss next.</p><pre>from typing import Any<br>from .config import GrumpyGuardConfig<br><br>async def get_provider_impl(config: GrumpyGuardConfig, deps: dict[str, Any]):<br>    from .grumpy_guard import GrumpyGuardSafetyImpl<br><br>    impl = GrumpyGuardSafetyImpl(config, deps)<br>    await impl.initialize()<br>    return impl</pre><h4>config.py</h4><p>We must define a configuration class for our external provider, however since grumpy-guard does not require any configuration the function will not do anything.</p><pre>from typing import Any<br>from pydantic import BaseModel<br><br>class GrumpyGuardConfig(BaseModel):<br>    @classmethod<br>    def sample_run_config(cls, __distro_dir__: str, **kwargs: Any) -&gt; dict[str, Any]:<br>        return {}</pre><h4>grumpy_guard.py</h4><p>Now we get into the meat of our external provider, grumpy_guard.py here we must define the following 4 functions:</p><ul><li>initialize()</li><li>shutdown()</li><li>register_shield(shield)</li><li>run_shield(shield_id, messages, params)</li></ul><p>For all the functions except run_shield we do not have to add any functionality as that is outside the scope of this demo. In run_shield we will keep it very simple.</p><p>For every time the shield is run (which will be every question asked) it will report a violation before moving on to the inference server.</p><pre>import logging<br>from typing import Any<br><br>from llama_stack.apis.inference import Message<br>from llama_stack.apis.safety import (<br>    RunShieldResponse,<br>    Safety,<br>    SafetyViolation,<br>    ViolationLevel,<br>)<br>from llama_stack.apis.shields import Shield<br>from llama_stack.providers.utils.inference.prompt_adapter import (<br>    interleaved_content_as_str,<br>)<br><br>from .config import GrumpyGuardConfig<br><br>log = logging.getLogger(__name__)<br><br>class GrumpyGuardSafetyImpl(Safety):<br>    def __init__(self, config: CustomGuardConfig, deps) -&gt; None:<br>        self.config = config<br><br>    async def initialize(self) -&gt; None:<br>        pass<br><br>    async def shutdown(self) -&gt; None:<br>        pass<br><br>    async def register_shield(self, shield: Shield) -&gt; None:<br>        pass<br><br>    async def run_shield(<br>        self,<br>        shield_id: str,<br>        messages: list[Message],<br>        params: dict[str, Any] = None,<br>    ) -&gt; RunShieldResponse:<br>        violation = SafetyViolation(<br>            violation_level=(ViolationLevel.ERROR),<br>            user_message=&quot;Sorry, what you are doing is dumb :)&quot;,<br>            metadata={},<br>        )<br>        return RunShieldResponse(violation=violation)</pre><h3>Installing the Package</h3><p>Now that the package has been set up we can add the package to our environment by running the following command from our package directory (lama-stack-provider-grumpy-guard).</p><pre>pip install -e .</pre><h3>Adding Provider Specification</h3><p>Now in order to have your newly created external provider package picked up by llama-stack you have to add a provider specification to a predetermined directory. Universally this directory is ~/.llama/providers.d however we will be creating our own providers.d directory.</p><p>providers.d must also follow the following file structure:</p><pre>providers.d/<br>  remote/<br>    inference/<br>      custom_ollama.yaml<br>      vllm.yaml<br>    vector_io/<br>      qdrant.yaml<br>    safety/<br>      llama-guard.yaml<br>  inline/<br>    inference/<br>      custom_ollama.yaml<br>      vllm.yaml<br>    vector_io/<br>      qdrant.yaml<br>    safety/<br>      llama-guard.yaml</pre><p>Since we are only adding one external safety provider this you can run the following commands:</p><pre>mkdir -p providers.d/inline/safety</pre><p>The specified provider type is inline as the provider will be run locally and not need any remote accesses.</p><p>Now in the directory that was just created make a file called grumpy-guard.yaml and add the following code into it:</p><pre>module: llama_stack_provider_grumpy_guard<br>config_class: llama_stack_provider_grumpy_guard.GrumpyGuardConfig<br>pip_packages: []<br>api_dependencies: []<br>optional_api_dependencies: []</pre><h3>Configure the “Stack”</h3><p>Now that the provider specification has been added we can configure the llama-stack’s run.yml.</p><pre>version: &#39;2&#39;<br>image_name: llamastack-learn-external-providers<br>container_image: null<br><br>external_providers_dir: ./providers.d/<br><br>apis:<br>  - inference<br>  - telemetry<br>  - agents<br>  - safety<br>  - vector_io<br>  - tool_runtime<br><br>providers:<br>  inference:<br>    - provider_id: openai<br>      provider_type: remote::openai<br>      config:<br>        api_key: ${env.OPENAI_API_KEY}<br>  telemetry:<br>    - provider_id: meta-reference<br>      provider_type: inline::meta-reference<br>      config:<br>        sinks: [&#39;console&#39;]<br>  agents:<br>    - provider_id: meta-reference<br>      provider_type: inline::meta-reference<br>      config:<br>        persistence_store:<br>          type: sqlite<br>          namespace: null<br>          db_path: ./agents_store.db<br>  safety:<br>    - provider_id: grumpy-guard<br>      provider_type: inline::grumpy-guard<br>      config: {}<br><br>models:<br>  - model_id: gpt-4-turbo<br>    provider_id: openai<br>    model_type: llm<br>    provider_model_id: gpt-4-turbo<br><br>server:<br>  port: 8321</pre><p>As you can see it is very similar to configuring a “stack” without external providers except for the line external_providers_dir: ./providers.d/. This line defines the directory that llama-stack should look for external providers in.</p><p>Also when using the external provider you can see that is configured in the same way as any other provider that is built in to llama-stack.</p><h3>Running the “Stack”</h3><p>In order to run the llama-stack use the following command:</p><pre>llama stack run run.yml</pre><p>Now in order to test if your external provider is working as expected you can create a script called chat.py that will create an agent and allow you to talk with it through llama-stack. The code for chat.py is shown below:</p><pre>import os<br><br>import fire<br>from llama_stack_client import LlamaStackClient<br>from llama_stack_client.lib.agents.agent import Agent<br>from llama_stack_client.lib.agents.event_logger import EventLogger<br>from llama_stack_client.types.agent_create_params import AgentConfig<br>from termcolor import colored<br><br><br>def main(host: str, port: int):<br><br>    client = LlamaStackClient(<br>        base_url=f&quot;http://{host}:{port}&quot;,<br>    )<br><br>    available_models = [<br>        model.identifier for model in client.models.list() if model.model_type == &quot;llm&quot;<br>    ]<br><br>    if not available_models:<br>        print(colored(&quot;No available models. Exiting.&quot;, &quot;red&quot;))<br>        return<br>    else:<br>        selected_model = available_models[0]<br>        print(f&quot;Using model: {selected_model}&quot;)<br><br>    client.shields.register(shield_id=&quot;grumpy-guard-shield&quot;, provider_shield_id=&quot;grumpy-guard&quot;)<br><br>    agent = Agent(<br>        client=client,<br>        model=selected_model,<br>        instructions=&quot;You are a helpful assistant.&quot;,<br>        sampling_params={<br>            &quot;strategy&quot;: {&quot;type&quot;: &quot;top_p&quot;, &quot;temperature&quot;: 1.0, &quot;top_p&quot;: 0.9},<br>        },<br>        tools=[],<br>        input_shields=[&quot;grumpy-guard-shield&quot;],<br>        output_shields=[],<br>        enable_session_persistence=False,<br>    )<br>    session_id = agent.create_session(&quot;test-session&quot;)<br><br>    while True:<br>        prompt = input(&quot;Enter a prompt: &quot;)<br>        if not prompt:<br>            break<br>        response = agent.create_turn(<br>            messages=[<br>                {<br>                    &quot;role&quot;: &quot;user&quot;,<br>                    &quot;content&quot;: prompt,<br>                }<br>            ],<br>            session_id=session_id,<br>        )<br><br>        for log in EventLogger().log(response):<br>            log.print()<br><br><br>if __name__ == &quot;__main__&quot;:<br>    fire.Fire(main)</pre><p>As you can see we first register the shield</p><pre>client.shields.register(shield_id=&quot;grumpy-guard-shield&quot;, provider_shield_id=&quot;grumpy-guard&quot;)</pre><p>And then add it to our agents input_shields</p><pre>agent = Agent(<br>        client=client,<br>        model=selected_model,<br>        instructions=&quot;You are a helpful assistant.&quot;,<br>        sampling_params={<br>            &quot;strategy&quot;: {&quot;type&quot;: &quot;top_p&quot;, &quot;temperature&quot;: 1.0, &quot;top_p&quot;: 0.9},<br>        },<br>        tools=[],<br>        input_shields=[&quot;grumpy-guard-shield&quot;],<br>        output_shields=[],<br>        enable_session_persistence=False,<br>    )</pre><p>Now we can run chat.py with the following command:</p><pre>python chat.py localhost 8321</pre><p>Any time you send a prompt you will immediately be returned with:</p><pre>shield_call&gt; {} Sorry, what you are doing is dumb :)</pre><p>Now you should be able to make external providers for your llama-stack! Thanks to <a href="https://medium.com/u/b9d432fe8acc">Lance Galletti</a> for all the help with learning the in’s and out’s of llama-stack!</p><p>All the code can be accessed <a href="https://github.com/jrobertboos/learn-external-providers">here</a>. Bye!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=17d1af4365aa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MCP with llama-stack]]></title>
            <link>https://medium.com/@j.robert.boos/mcp-with-llama-stack-984615403b6d?source=rss-49efbda44c8b------2</link>
            <guid isPermaLink="false">https://medium.com/p/984615403b6d</guid>
            <category><![CDATA[llama-stack]]></category>
            <category><![CDATA[mcp-server]]></category>
            <dc:creator><![CDATA[John Boos]]></dc:creator>
            <pubDate>Thu, 29 May 2025 20:01:50 GMT</pubDate>
            <atom:updated>2025-05-29T20:01:50.349Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post is an extension of </em><a href="https://medium.com/@gallettilance/llama-stack-101-15b28752311b"><em>Lance Galletti’s post</em></a><em> on building a simple llama-stack server. We will discuss setting up a llama-stack with the ability to use tools through MCP. Integrating MCP into llama-stack allows for huge value by providing an interface for an LLM to interact and communicate with real world entities.</em></p><h3>Required Dependencies</h3><p>Run the following line to install all the required dependencies.</p><pre>pip install -r https://raw.githubusercontent.com/jrobertboos/learn-mcp/refs/heads/main/requirements.txt</pre><h3>Configure the “stack”</h3><p>In order to start a llama-stack a configuration must be given. This configuration specifies the available APIs, providers, and resources.</p><p>Below is a simple configuration file, run.yml. This configuration file provides all the necessary API’s, provides, and resources to run a basic agent using the OpenAI GPT-4-Turbo inference server.</p><pre>version: &#39;2&#39;<br>image_name: llamastack-learn-mcp<br>container_image: null<br><br>apis:<br>  - inference<br>  - telemetry<br>  - tool_runtime<br>  - agents<br>  - safety<br>  - vector_io<br><br>providers:<br>  inference:<br>    - provider_id: openai<br>      provider_type: remote::openai<br>      config:<br>        api_key: ${env.OPENAI_API_KEY}<br>  telemetry:<br>    - provider_id: meta-reference<br>      provider_type: inline::meta-reference<br>      config:<br>        sinks: [&#39;console&#39;]<br>  agents:<br>    - provider_id: meta-reference<br>      provider_type: inline::meta-reference<br>      config:<br>        persistence_store:<br>          type: sqlite<br>          namespace: null<br>          db_path: ./agents_store.db<br><br>models:<br>  - model_id: gpt-4-turbo<br>    provider_id: openai<br>    model_type: llm<br>    provider_model_id: gpt-4-turbo<br>server:<br>  port: 8321</pre><p>Before proceeding with running the llama-stack you will need to enter your OpenAI API key, you can accomplish this by running the following line.</p><pre>export OPENAI_API_KEY=&quot;paste-your-key-here&quot;</pre><h3>Run the “stack”</h3><p>Now that the “stack” has been configured we will be able to run it. This can be done by running the following command.</p><pre>llama stack run run.yml</pre><p>After the above command is run your llama-stack server should successfully run.</p><p>Now that the “stack” is up and running we want to test it by being able to chat with it. To do this we will write a program that uses llama-stack-client in order to create an agent and provide an interface to chat with it.</p><p>The code for this, chat.py, is shown below.</p><pre>import os<br><br>import fire<br>from llama_stack_client import LlamaStackClient<br>from llama_stack_client.lib.agents.agent import Agent<br>from llama_stack_client.lib.agents.event_logger import EventLogger<br>from llama_stack_client.types.agent_create_params import AgentConfig<br>from termcolor import colored<br><br><br>def main(host: str, port: int):<br><br>    client = LlamaStackClient(<br>        base_url=f&quot;http://{host}:{port}&quot;,<br>    )<br><br>    available_models = [<br>        model.identifier for model in client.models.list() if model.model_type == &quot;llm&quot;<br>    ]<br><br>    if not available_models:<br>        print(colored(&quot;No available models. Exiting.&quot;, &quot;red&quot;))<br>        return<br>    else:<br>        selected_model = available_models[0]<br>        print(f&quot;Using model: {selected_model}&quot;)<br><br>    agent = Agent(<br>        client=client,<br>        model=selected_model,<br>        instructions=&quot;You are a helpful assistant.&quot;,<br>        sampling_params={<br>            &quot;strategy&quot;: {&quot;type&quot;: &quot;top_p&quot;, &quot;temperature&quot;: 1.0, &quot;top_p&quot;: 0.9},<br>        },<br>        tools=[],<br>        input_shields=[],<br>        output_shields=[],<br>        enable_session_persistence=False,<br>    )<br>    session_id = agent.create_session(&quot;test-session&quot;)<br><br>    while True:<br>        prompt = input(&quot;Enter a prompt: &quot;)<br>        if not prompt:<br>            break<br>        response = agent.create_turn(<br>            messages=[<br>                {<br>                    &quot;role&quot;: &quot;user&quot;,<br>                    &quot;content&quot;: prompt,<br>                }<br>            ],<br>            session_id=session_id,<br>        )<br><br>        for log in EventLogger().log(response):<br>            log.print()<br><br><br>if __name__ == &quot;__main__&quot;:<br>    fire.Fire(main)</pre><p>You should now be able to chat with the server by running chat.py with the following command.</p><pre>python chat.py localhost 8321</pre><h3>Create the MCP server</h3><p>In order to extend the functionality of our llama-stack we can create a MCP server to provide tools that our agents can utilize. For the purpose of this tutorial we will create a simple MCP server using FastMCP which is included in the <a href="https://github.com/modelcontextprotocol/python-sdk">MCP Python SDK</a> (it will already be installed assuming you installed the required dependencies).</p><p>The MCP server that we will create will list the files contained in the “Recipes” directory. This is a toy example to demonstrate tool usage and execution. The code for the MCP server is shown below.</p><pre>&quot;&quot;&quot;<br>FastMCP File Lister Example<br><br>A simple example that exposes and lists the contents of the <br>&quot;Recipes&quot; directory as a tool.<br>&quot;&quot;&quot;<br><br>from pathlib import Path<br><br>from mcp.server.fastmcp import FastMCP<br><br># Create server<br>mcp = FastMCP(&quot;Demo&quot;)<br><br>@mcp.tool()<br>def recipes_list_tool() -&gt; str:<br>    &quot;&quot;&quot;List the recipes files names in the user&#39;s recipe folder as a tool&quot;&quot;&quot;<br>    desktop = Path.cwd() / &quot;Recipes&quot;<br>    return [str(f) for f in desktop.iterdir()]<br><br>if __name__ == &quot;__main__&quot;:<br>    mcp.run(transport=&quot;sse&quot;)</pre><p>Once you have made the MCP server you can start running it but before that make sure that the “Recipes” directory exists in the CWD and contains files named with whatever recipe names you want (e.g “Apple Pie”, “Brisket”).</p><h3>Modify “Stack” Configuration</h3><p>In order to use the tools provided by the MCP server we just created we must modify the run.yml we previously made. The new run.yml is shown below<strong>.</strong> The added components are the <strong>tool_runtime</strong> provider and the <strong>tool_groups</strong> resource.</p><pre>version: &#39;2&#39;<br>image_name: llamastack-learn-mcp<br>container_image: null<br><br>apis:<br>  - inference<br>  - telemetry<br>  - tool_runtime<br>  - agents<br>  - safety<br>  - vector_io<br><br>providers:<br>  inference:<br>    - provider_id: openai<br>      provider_type: remote::openai<br>      config:<br>        api_key: ${env.OPENAI_API_KEY}<br>  telemetry:<br>    - provider_id: meta-reference<br>      provider_type: inline::meta-reference<br>      config:<br>        sinks: [&#39;console&#39;]<br><strong>  tool_runtime:<br>    - provider_id: model-context-protocol<br>      provider_type: remote::model-context-protocol<br>      config: {}<br></strong>  agents:<br>    - provider_id: meta-reference<br>      provider_type: inline::meta-reference<br>      config:<br>        persistence_store:<br>          type: sqlite<br>          namespace: null<br>          db_path: ./agents_store.db<br><br>models:<br>  - model_id: gpt-4-turbo<br>    provider_id: openai<br>    model_type: llm<br>    provider_model_id: gpt-4-turbo<br><strong>tool_groups:<br>  - toolgroup_id: mcp::recipes<br>    provider_id: model-context-protocol<br>    mcp_endpoint:<br>      uri: &quot;http://localhost:8000/sse&quot;<br></strong>server:<br>  port: 8321</pre><p>Once you have your “stack” configuration updated I would recommend removing the persisted information from the original llama-stack. To do this run the following commands.</p><pre>rm -r ~/.llama/llamastack-learn-mcp</pre><p>If you also want to remove the persisted agents you can delete the agent_store.db file.</p><h3>Running the Updated “Stack”</h3><p>Just as before to run the updated llama-stack run the following command.</p><pre>llama stack run run.yml</pre><p>Now in order to chat with an agent that can make use of the tools provided by our “Recipes” MCP server we must modify how the agent is created in chat.py. The updated agent creation in chat.py is shown below.</p><pre>    agent = Agent(<br>        client=client,<br>        model=selected_model,<br>        instructions=&quot;You are a helpful assistant.&quot;,<br>        sampling_params={<br>            &quot;strategy&quot;: {&quot;type&quot;: &quot;top_p&quot;, &quot;temperature&quot;: 1.0, &quot;top_p&quot;: 0.9},<br>        },<br>        tools=[&quot;mcp::recipes&quot;],<br>        input_shields=[],<br>        output_shields=[],<br>        enable_session_persistence=False,<br>    )</pre><p>Now just as before you can run chat.py except now you can ask it questions like “<em>What recipes do I have?</em>” and see how the tool is called and how the agent responds with the information received by the tool.</p><p>Now you should be able to build MCP servers of your own and connect them with your llama-stack! Thank you <a href="https://medium.com/u/b9d432fe8acc">Lance Galletti</a> for all the help!</p><p>All the code can be accessed <a href="https://github.com/jrobertboos/learn-mcp/">here</a>. Bye!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=984615403b6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>