Mahilo As Your Agent Control Plane
With the advent of increasingly powerful models, the use of specialized agents would grow considerably. We already have powerful agents that you can hire for your organization, performing tasks like marketing, sales or product management. In a world where these agents are expected to work together, it becomes important that they are aware of each other and can share information as needed to get better at their jobs, instead of working in silos.
mahilo is a multi-agent human-in-the-loop framework that ties agents together while allowing humans to supervise them in real-time. Bring any agent, irrespective of the framework it is written in (or from a proprietary service) and mahilo can enable you to connect it to your team of agents, allowing cross-communication and enforcement of common company policies.
Let's look at an example using LangGraph and PydanticAI agents (the two frameworks supported at the moment).
Use Case: Sales, Marketing, and Product Teams in a Company
Let's take the use case of a company with three teams that need to coordinate with each other across multiple tasks. The scenario we will focus on is this: Feature Launch Coordination.
The setup is such that each team gets an agent that is supervised by a human supervisor. We will start our discourse with the sales agent about a potential new feature, which will then use its capabilities to decide what course of action to take, eventually discussing the idea and its roadmap with the product agent, which in turn gets the marketing agent in the loop for preparing promotion material. All of this, while their human supervisors have direct knowledge of what's going on and can guide and approve the agents' actions.
Building the Agents
Setup
Let's first install some libraries and set our OpenAI API key, which is the provider we will use for the demo.
Run to view results
Run to view results
Marketing Agent (LangGraph)
We'll start with the marketing agent and will utilize LangGraph to build it. To build an agent that can be registered with mahilo later, all you need to do is add a tool that mahilo provides, to your ToolNode when defining your graph.
You can then go about building the agent without worrying about any additional syntax and choose whatever tools suit your needs. In the example below, we have chosen three tools for the marketing agent:
We expect this agent to answer questions about what platforms have performed well, what is the current market sentiment around relevant topics and to generate content calendars based on all the information it gathers. You can imagine that this agent will benefit from knowing specific product details when choosing what to promote, from the product team and also where most sales leads are coming from, from the sales team.
Run to view results
The code above builds a simple graph that starts at the chatbot and has a tools node that is called conditionally if the response of the chatbot contains any tool calls. The functions have dummy logic but you can imagine that this agent in production could be a state-of-the-art, well-tested system that specializes in marketing.
âšī¸ mahilo also supports setting thread ID when running the agent. We will see this in the control plane section below when we bring these agents together.
Run to view results
Product Agent (PydanticAI)
The next agent we will build is a product manager agent, built using PydanticAI. To build an agent that can later be integrated into mahilo, you don't have to perform any additional tasks! mahilo can take your PydanticAI agent as it is, and integrate it into its network of AI agents.
The product agent below has the following functions:
We expect this agent to be able to analyze a feature request, figure out when it is planned and then discuss with its human supervisor if it needs to be reprioritized. It can also analyze patterns and come up with features to build. You can imagine that this agent would be really helpful for the sales agent to get up-to-date information about the product and motivate priorities based on customer feedback. This agent also has to work closely with the marketing team to keep them in the loop for upcoming features.
Run to view results
The code above defines a product agent that has some product dependencies that should be injected at runtime, like the project name and the database connection. mahilo supports passing them in when activating your mahilo agents, something we will see in the control plane section below.
The output of the model is also expected to follow the FeatureAnalysis model that is defined with parameters like human review requests and other comments. The mahilo agent in the websocket connection respects this and also formats this correctly for easy viewing.
Sales Agent (mahilo)
Let's now build our final agent, the sales agent that will be built using mahilo natively. To create agents in mahilo, all you need to do is define a dictionary that links your tool definitions (in OpenAI spec) and your Python functions together and then we can use the `BaseAgent` class to define an instance of our agent.
The sales agent has the following functions:
We expect the sales agent to be able to answer questions about the source of leads coming in, to collect feedback on features from the users they talk to and identify trends and then generate insights based on this data. You can imagine that the source of leads is an interesting metric for the marketing team to refocus efforts when pushing content out, and the product team can benefit immensely from the feedback from real users on what feature to prioritize next.
Run to view results
The code above defines our tools and the Python functions. We can now use it in our BaseAgent in the section below.
Control Plane For Your Agents
Once you have the independent agents ready and functional, the ideal next step is to bring them together in a team where they can choose to interact with other agents as the need arises. This expands their scope and makes them more useful as opposed to working in silos without knowledge of the company at large.
One other benefit of a control plane like this is that you can enforce company-wide policies like ethics, and communication patterns among others. Let's look at the code below to see how mahilo enables this realtime collaboration between your agents.
Run to view results
When defining mahilo agents for your LangGraph and PydanticAI agents, you just have to wrap your agent instances in the classes that mahio provides, LangGraphAgent and PydanticAIAgent respectively. You can provide a name to your agents, which is what will be visible to the other agents when they want to communicate, and a description which will be dynamically added to the main system prompt. This description helps facilitate the communication and makes the agents aware of the team they are now in.
When adding your agent to mahilo, you get the following benefits:
Starting The Server
Now, once you have defined your server with your team of agents, you can start it to spawn a websocket server that you can connect to using your terminal.
Run to view results
Connecting to The Server
With the server running, go to the Terminals section on the left pane and start a new terminal. You can connect to your mahilo server using the command below.
Run to view results
You can spin up different terminals for each of the agents, changing the --agent-name flag to fit the agent you wanna establish a channel with.
âšī¸ By default, the client connects to localhost:8000 but in scenarios where you choose to deploy it remotely, you can pass in the host with the --host flag.