The Agent Communication Protocol (ACP) is an open regular designed to permit seamless communication between AI brokers, features, and folks. As AI methods are typically developed using quite a few frameworks and infrastructures, they’ll end up isolated and incompatible, limiting their ability to collaborate. ACP addresses this fragmentation by offering a unified RESTful API that facilitates:
- Multimodal communication
- Every synchronous and asynchronous messaging
- Precise-time streaming
- Help for stateful and stateless agent interactions
- Discovery of brokers, whether or not or not on-line or offline
- Execution of long-running duties
On this tutorial, we’ll take our first steps with ACP by setting up a main server that offers London’s local weather information and a straightforward client that will work along with it.
Organising the dependencies
Placing within the libraries
pip arrange acp acp-sdk beeai-framework httpx
Creating the ACP Server
We’ll begin by organising the ACP server, starting with the creation of an agent.py file.
We’ll begin by importing the necessary libraries. To fetch London’s local weather information, we’ll use the httpx library to make a request to the Open‑Meteo API.
import asyncio
from collections.abc import AsyncGenerator
import httpx
from acp_sdk.fashions import Message, MessagePart
from acp_sdk.server import Context, RunYield, RunYieldResume, Server
server = Server()
Subsequent, we’ll define an asynchronous helper function known as get_london_weather that retrieves the current local weather in London using the Open‑Meteo API. This function sends a request with London’s coordinates and returns a formatted local weather summary along with temperature, wind tempo, and local weather scenario code.
async def get_london_weather() -> str:
"""Fetch current London local weather from the free Open‑Meteo API."""
params = {
"latitude": 51.5072, # London coordinates
"longitude": -0.1276,
"current_weather": True,
"timezone": "Europe/London"
}
url = "https://api.open-meteo.com/v1/forecast"
async with httpx.AsyncClient(timeout=10) as client:
resp = await client.get(url, params=params)
resp.raise_for_status()
cw = resp.json()["current_weather"]
return (
f"Local weather in London: {cw['temperature']} °C, "
f"wind {cw['windspeed']} km/h, code {cw['weathercode']}."
)
This code defines an ACP-compatible agent using the @server.agent() decorator. The london_weather_agent function handles incoming messages by first yielding a thought message, then asynchronously fetching the current local weather in London using the get_london_weather() helper. The local weather information is then returned as a plain textual content material message. Lastly, server.run() begins the ACP server and makes the agent accessible to take care of requests
@server.agent()
async def london_weather_agent(
enter: itemizing[Message], context: Context
) -> AsyncGenerator[RunYield, RunYieldResume]:
"""Returns current London local weather."""
for _ in enter:
yield {"thought": "Fetching London local weather..."}
local weather = await get_london_weather()
yield Message(
place="agent",
parts=[MessagePart(content=weather, content_type="text/plain")]
)
server.run()
Working the server
Subsequent, we’ll run the agent.py file to start the server. As quickly as working, the ACP agent might be accessible to take care of requests at http://localhost:8000
To substantiate that your agent is up and working, open a model new terminal and execute the following curl command:
curl http://localhost:8000/brokers
If all of the items is working appropriately, you’ll acquire a JSON response itemizing your agent, confirming that it’s accessible and in a position to take care of requests.
{
"brokers": [
{
"name": "london_weather_agent",
"description": "Returns current London weather.",
"metadata": {
"annotations": null,
"documentation": null,
"license": null,
"programming_language": null,
"natural_languages": null,
"framework": null,
"capabilities": null,
"domains": null,
"tags": null,
"created_at": null,
"updated_at": null,
"author": null,
"contributors": null,
"links": null,
"dependencies": null,
"recommended_models": null
},
"input_content_types": [
"*/*"
],
"output_content_types": [
"*/*"
]
}
]
}
Creating the ACP Client
We’ll now create an ACP client (client.py) to work along with our server.
This client script makes use of the ACP SDK to hook up with the domestically working london_weather_agent via the ACP server at http://localhost:8000. It sends a synchronous message asking for the local weather using the run_sync methodology. As quickly because the agent responds, the script prints out the returned local weather particulars.
import asyncio
from acp_sdk.client import Client
from acp_sdk.fashions import Message, MessagePart
async def call_london_weather_agent() -> None:
async with Client(base_url="http://localhost:8000") as client:
run = await client.run_sync(
agent="london_weather_agent",
enter=[
Message(
parts=[MessagePart(content="Tell me the weather", content_type="text/plain")]
)
],
)
print("Response from london_weather_agent:")
for message in run.output:
for half in message.parts:
print("-", half.content material materials)
if __name__ == "__main__":
asyncio.run(call_london_weather_agent())
Working the Client
In a single different terminal, run the following command to ship request to our ACP server
It’s greatest to see a response from the server containing the current local weather in London, returned by the london_weather_agent.
Response from london_weather_agent:
- Local weather in London: 20.8 °C, wind 10.1 km/h, code 3.
Attempt the Codes. All credit score rating for this evaluation goes to the researchers of this problem. Moreover, be at liberty to adjust to us on Twitter, Youtube and Spotify and don’t neglect to affix our 100k+ ML SubReddit and Subscribe to our Publication.
I’m a Civil Engineering Graduate (2022) from Jamia Millia Islamia, New Delhi, and I’ve a keen curiosity in Data Science, notably Neural Networks and their software program in various areas.
Keep forward of the curve with NextBusiness 24. Discover extra tales, subscribe to our e-newsletter, and be a part of our rising neighborhood at nextbusiness24.com

