Fasta2a

0.6.0 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates how to create a basic Fasta2a application by initializing `Fasta2aApp` and defining an asynchronous message handler using the `@app.handle_message()` decorator. The handler processes `AgentMessage` objects and returns `AgentResponse` objects, optionally including `ToolCall`s. The example also shows how to run the application using `uvicorn`.

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.

view raw JSON →