Fasta2a
Fasta2a (current version 0.6.0) is a Python library that converts an AI Agent into an A2A (Agent-to-Agent) server. It facilitates communication between AI agents by implementing the A2A protocol, allowing agents to expose their capabilities and interact programmatically. The library is relatively new but actively developed, with releases occurring every few months as the protocol specification evolves.
Warnings
- breaking The A2A protocol version support changes between `fasta2a` releases. For example, `v0.6.0` introduced support for `protocolVersion 0.3.0`. Older versions of `fasta2a` may not be compatible with newer protocol versions, and vice-versa, leading to parsing errors or unexpected agent behavior.
- gotcha The core A2A schemas (`AgentMessage`, `AgentResponse`, `ToolCall`, `StreamMessageResponse`, etc.) are actively evolving as the protocol matures. Code relying on specific schema fields or structures might require updates with new `fasta2a` releases.
- gotcha Fasta2a applications are ASGI applications and must be run with a compatible ASGI server (e.g., `uvicorn`) to be accessible. Simply running the Python script will define the application object but will not serve it over HTTP.
Install
-
pip install fasta2a
Imports
- Fasta2aApp
from fasta2a.app import Fasta2aApp
- AgentMessage
from fasta2a.schema import AgentMessage
- AgentResponse
from fasta2a.schema import AgentResponse
- ToolCall
from fasta2a.schema import ToolCall
- StreamMessageResponse
from fasta2a.schema import StreamMessageResponse
Quickstart
import uvicorn
from fasta2a.app import Fasta2aApp
from fasta2a.schema import AgentMessage, AgentResponse, ToolCall
app = Fasta2aApp()
@app.handle_message()
async def my_agent_handler(message: AgentMessage) -> AgentResponse:
"""Handles incoming AgentMessage and returns an AgentResponse."""
print(f"Received message: {message.body}")
if message.body == "hello":
return AgentResponse(body="world")
elif message.body == "call_tool":
return AgentResponse(
body="I am calling a hypothetical tool!",
toolCalls=[
ToolCall(
name="my_example_tool",
arguments={"param1": "value1", "param2": 123}
)
]
)
return AgentResponse(body=f"Unknown message: {message.body}")
# To run this application, save it as, e.g., `main.py`
# and execute from your terminal:
# uvicorn main:app --host 0.0.0.0 --port 8000
# Then you can interact with it using an A2A client.