File size: 1,261 Bytes
126d4ef
bb3a1e6
126d4ef
bb3a1e6
126d4ef
 
 
 
 
bb3a1e6
126d4ef
 
 
 
bb3a1e6
126d4ef
bb3a1e6
126d4ef
 
 
 
 
 
 
bb3a1e6
 
126d4ef
 
 
 
 
 
 
 
 
 
bb3a1e6
126d4ef
 
 
bb3a1e6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# main.py
import os
import uvicorn

# ---- Adjust imports to match a2a-python ----
# These paths are common in the tutorial; if yours differ, change them accordingly.
from a2a.server.apps import A2AStarletteApplication
from a2a.server.request_handlers import DefaultRequestHandler
from a2a.server.tasks import InMemoryTaskStore

# Example minimal executor
class HelloWorldAgentExecutor:
    async def call(self, message: str, **kwargs):
        return {"text": f"Hello from A2A on HF Spaces! You said: {message}"}

# Example minimal public AgentCard (adjust fields to your spec)
AGENT_CARD = {
    "name": "HF A2A Agent",
    "version": "1.0",
    "description": "A2A demo running on Hugging Face Spaces",
    "endpoints": {
        "send": "/message/send",
        "stream": "/message/stream"
    }
}

def build_app():
    app = A2AStarletteApplication(
        agent_card=AGENT_CARD,
        http_handler=DefaultRequestHandler(
            agent_executor=HelloWorldAgentExecutor(),
            task_store=InMemoryTaskStore(),
        ),
        # extended_agent_card=...  # optional
    ).build()
    return app

if __name__ == "__main__":
    port = int(os.getenv("PORT", "7860"))  # HF provides PORT
    uvicorn.run(build_app(), host="0.0.0.0", port=port)