TaskRunner. We subclass the base TaskRunner to create a TranslationTaskRunner with a defined input schema, output schema, and ask() method. This allows us to keep the existing logic from the Pydantic AI agent and run it inside a MeshAgent room. The sample uses the MeshAgent room router for Anthropic access, so credentials are supplied by your project configuration.
Prerequisites
- Python venv with
meshagentandpydantic_aiinstalled - Authenticate to MeshAgent
meshagent setup
Step 1: Create the TaskRunner
Copy this code into a file calledtranslator.py. This example uses the MeshAgent room router to supply Anthropic credentials, so you do not need a local ANTHROPIC_API_KEY. If you are not using the room router, update the provider to use your own Anthropic key or swap in a different model/provider.
Step 2: Run locally
From the terminal start your service locally. Be sure you are in an activated virtual environment where meshagent and pydantic_ai are installed:bash
Step 3: Invoke and Test the TaskRunner
You can test the TaskRunner by invoking it from MeshAgent Studio, the CLI, or SDK code. If you want to make changes to the agent you can runCtrl+C to stop the service from running, update it, then restart the service. If you want the service to persist you will need to deploy it (see Step 4).
Invoking from the Studio
- Go to MeshAgent Studio
- Enter the room
translate - Click the upper left menu —> “Toolkits”
- Select translator from the agent dropdown
- Enter the text to translate (you will ned to supply the JSON schema e.g.
{"text":"How are you today?"}) - Results appear and are saved to room storage under the “translations” folder
Invoking from the CLI or Code
From the CLI While the service is running, create a new tab in your terminal and run:CLI
invoke_translator.py. This will establish the connection to the room and allow you to run the TranslationTaskRunner.
bash
Step 4: Deploy as a service
To persist the agent you will need to deploy it to your room. This sample uses a single image so the container includes thepydantic_ai dependency.
Dockerfile (single image)
Build from the sample folder so the Dockerfile copies the translator files into the image.
bash
Note: If you build your own image, we recommend optimizing it with eStargz for faster pulls.meshagent.yaml Define the service configuration in a
meshagent.yaml file. This service references your single image and runs the TaskRunner entrypoint.
meshagent.yaml file is run:
bash
Next Steps
- TaskRunner Overview: Understand TaskRunners and how to use them
- Services & Containers: Understand different options for running, deploying, and managing agents with MeshAgent
- Secrets & Registries: Learn how to store credentials securely for deployment