Agent Communication Protocol (ACP) is a standard for agent-to-agent communication, allowing different AI agents to interact regardless of how they’re built. This agent works with any ACP-compliant service.
The availability of ACP agents depends on the server you’re connecting to. You can check which agents are available by using the check_agent_exists method:
Copy
Ask AI
try: await agent.check_agent_exists() print("Agent exists and is available")except AgentError as e: print(f"Agent not available: {e.message}")
If you need to create your own ACP server with custom agents, BeeAI framework provides the AcpServer class.
from beeai_framework.adapters.acp import ACPServer, ACPServerConfigfrom beeai_framework.agents.experimental import RequirementAgentfrom beeai_framework.backend import ChatModelfrom beeai_framework.memory import UnconstrainedMemoryfrom beeai_framework.tools.search.duckduckgo import DuckDuckGoSearchToolfrom beeai_framework.tools.weather import OpenMeteoTooldef main() -> None: llm = ChatModel.from_name("ollama:granite3.3:8b") agent = RequirementAgent( llm=llm, tools=[DuckDuckGoSearchTool(), OpenMeteoTool()], memory=UnconstrainedMemory(), # specify the agent's name and other metadata name="my_agent", description="A simple agent", ) # Register the agent with the ACP server and run the HTTP server # For the ToolCallingAgent and ReActAgent, we dont need to specify ACPAgent factory method # because they are already registered in the ACPServer ACPServer(config=ACPServerConfig(port=8001)).register(agent, tags=["example"]).serve()if __name__ == "__main__": main()
Custom agent example:
Copy
Ask AI
import sysimport tracebackfrom collections.abc import AsyncGeneratorimport acp_sdk.models as acp_modelsimport acp_sdk.server.context as acp_contextimport acp_sdk.server.types as acp_typesfrom pydantic import BaseModel, InstanceOffrom beeai_framework.adapters.acp import ACPServerfrom beeai_framework.adapters.acp.serve._utils import acp_msgs_to_framework_msgsfrom beeai_framework.adapters.acp.serve.agent import ACPServerAgentfrom beeai_framework.adapters.acp.serve.server import to_acp_agent_metadatafrom beeai_framework.adapters.beeai_platform.serve.server import BeeAIPlatformServerMetadatafrom beeai_framework.agents.base import BaseAgentfrom beeai_framework.backend.message import AnyMessage, AssistantMessagefrom beeai_framework.context import Run, RunContextfrom beeai_framework.emitter.emitter import Emitterfrom beeai_framework.errors import FrameworkErrorfrom beeai_framework.memory import UnconstrainedMemoryfrom beeai_framework.memory.base_memory import BaseMemoryclass EchoAgentRunOutput(BaseModel): message: InstanceOf[AnyMessage]# This is a simple echo agent that echoes back the last message it received.class EchoAgent(BaseAgent[EchoAgentRunOutput]): memory: BaseMemory def __init__(self, memory: BaseMemory) -> None: super().__init__() self.memory = memory def _create_emitter(self) -> Emitter: return Emitter.root().child( namespace=["agent", "custom"], creator=self, ) def run( self, input: list[AnyMessage] | None = None, ) -> Run[EchoAgentRunOutput]: async def handler(context: RunContext) -> EchoAgentRunOutput: assert self.memory is not None if input: await self.memory.add_many(input) return EchoAgentRunOutput(message=AssistantMessage(self.memory.messages[-1].text)) return self._to_run(handler, signal=None)def main() -> None: # Create a custom agent factory for the EchoAgent def agent_factory(agent: EchoAgent, *, metadata: BeeAIPlatformServerMetadata | None = None) -> ACPServerAgent: """Factory method to create an ACPAgent from a EchoAgent.""" if metadata is None: metadata = {} async def run( input: list[acp_models.Message], context: acp_context.Context ) -> AsyncGenerator[acp_types.RunYield, acp_types.RunYieldResume]: framework_messages = acp_msgs_to_framework_msgs(input) response = await agent.run(framework_messages) yield acp_models.MessagePart(content=response.message.text, role="assistant") # type: ignore[call-arg] # Create an ACPAgent instance with the run function return ACPServerAgent( fn=run, name=metadata.get("name", agent.meta.name), description=metadata.get("description", agent.meta.description), metadata=to_acp_agent_metadata(metadata), ) # Register the custom agent factory with the ACP server ACPServer.register_factory(EchoAgent, agent_factory) # Create an instance of the EchoAgent with UnconstrainedMemory agent = EchoAgent(memory=UnconstrainedMemory()) # Register the agent with the ACP server and run the HTTP server # Enamble self-registration for the agent to BeeAI platform ACPServer(config={"self_registration": True}).register(agent, name="echo_agent").serve()if __name__ == "__main__": try: main() except FrameworkError as e: traceback.print_exc() sys.exit(e.explain())# run: beeai agent run echo_agent "Hello"