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.
Prerequisites
- Python venv with
meshagentandpydantic_aiinstalled - An LLM provider key (example uses
ANTHROPIC_API_KEY) - Authenticate to MeshAgent
meshagent setup
Example: Integrating a Pydantic AI Agent
Copy this code into a file calledtranslator.py. You will need to create and export an ANTHROPIC_API_KEY first for this to run. Or update the example to use a model from a different provider of your choice.
Running the TaskRunner
From the terminal start your service locally. Be sure you are in an activated virtual environment where meshagent and pydantic_ai are installed:bash
Invoking from the Studio
- Go to MeshAgent Studio
- Enter the room
translate - Click the upper left menu —> “Run Task”
- Select translator from the agent dropdown
- Enter the text to translate
- 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
Example: Using TaskRunner Agents as Agent Tools
TaskRunners can also be surfaced in toolkits and used as tools by other agents usingRunTaskTool. Exposing agents as tools and then giving those tools to a ChatBot is a great way to get started building multi-agent systems.
Let’s try this out by creating a new ChatBot and giving it a tool, the Pydantic AI translation agent that we defined above.
Creating the service with agents-as-tools
At the end of ourtranslator.py file let’s add A new ChatBot service and pass it the translator agent as a RequiredToolkit. This will allow us to chat with the ChatBot while the ChatBot uses the translator agent as a tool when necessary.
Python
ServiceHost will automatically discover and start both the translation agent and the chatbot since they are part of the same service.
bash
- Go to studio.meshagent.com
- Enter the room
translate - In the participants list, you’ll see the
chat-translator - Click on
chat-translatorto start chatting with the agent - Ask it something like: “Can you translate ‘Hello, how are you?’ for me?”
- The
chat-translatorwill automatically use thetranslatorPydantic AI TranslationTaskRunner as a tool to complete the request and you will see the JSON results added to the translations folder in the room storage.
Remember: You can still use the Pydantic AI TranslationTaskRunner directly since it is running in the room, this approach just demonstrates an easy way to use a TaskRunner agent as a tool for another agent.
Next Steps
Dive Deeper into TaskRunners- TaskRunner Overview: Review what TaskRunners are and when to use them
- Prebuilt MeshAgent TaskRunners: Learn how to use prebuilt TaskRunners that come out of the box with every MeshAgent room
- Create a Custom LLM TaskRunner: Build your own LLM-driven TaskRunner
- Services & Containers: Understand different options for running, deploying, and managing agents with MeshAgent
- Secrets & Registries: Learn how to store credentials securely for deployment