Skip to main content
Static services that should be the same across the project should be deployed as a project-wide service. These services are meant to be generic and not customized by room, they’re designed to provide shared functionality across rooms in a project. To learn more about project vs room services and understand when to use each see intro to services and containers.

Example

Let’s create a simple chatbot that can be deployed to all the rooms in our project. This will ensure everyone always has access to an LLM in any room inside the project. To deploy this we’ll create three files:
  • main.py: A MeshAgent-native chatbot service using ServiceHost
  • Dockerfile: Packages the service as a container
  • meshagent.yaml: A ServiceSpec that defines how to run the service

main.py

Python
import os
import asyncio
import logging
from meshagent.agents.chat import ChatBot
from meshagent.api.services import ServiceHost
from meshagent.openai import OpenAIResponsesAdapter

logging.basicConfig(level=logging.DEBUG)

host = ServiceHost()

@host.path(path="/agent", identity="chatbot")
class MyChatBot(ChatBot): 
    def __init__(self):
        super().__init__(
            name="chatbot",
            llm_adapter=OpenAIResponsesAdapter(),
        )

asyncio.run(host.run())

Dockerfile

Dockerfile
FROM meshagent/python-sdk-slim:latest

COPY . /src

WORKDIR /src

ENTRYPOINT [ "python3", "main.py" ]

meshagent.yaml

yaml
kind: Service
version: v1
metadata:
  name: chatbot
  description: "A simple chatbot that can interact with users"
agents:
  - name: chatbot
    description: "Project-wide conversational agent"
    annotations:
      meshagent.agent.type: "ChatBot"
ports:
- num: "*"
  type: http
  liveness: "/"
  endpoints:
  - path: /agent
    meshagent:
      identity: chatbot
container:
  image: "IMAGE:TAG"
For more details on the configuration files see the packaging services documentation. Don’t forget to add a pull_secret parameter to the container section of the manifest if you are pulling from a private repository.

Build and Push the Container

Now that we’ve defined our agent and written the applicable Dockerfile and meshagent.yaml let’s build and push the docker container to our registry.
docker buildx build . \
  -t "$IMAGE:$TAG" \
  --platform linux/amd64 \
  --push
Note: We recommend docker buildx because it supports cross-platform builds, pushes directly to your registry in one step, and enables optional layer caching for much faster CI builds.

Deploy the Project-Wide Service

From the terminal in the directory with your yaml file simply run:
bash
meshagent setup # authenticate to MeshAgent if not already done
meshagent service create --file="meshagent.yaml"
For more details on deployment see the deploying services documentation.

Use the Service

Now that your service is deployed try it out in MeshAgent Studio. You’ll see the new project service appear in the Services tab of the UI. To use the service, simply start a new session and enter the room, the chatbot will appear in the participants tab for you to interact with.