Sheyda Kiani Mehr commited on
Commit
bb3a1e6
·
1 Parent(s): 8bc1483

Add A2A server (Docker) for HF Space

Browse files
Files changed (3) hide show
  1. Dockerfile +15 -0
  2. main.py +41 -0
  3. requirements.txt +4 -0
Dockerfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM python:3.11-slim
2
+
3
+ # Optional: install system packages your agent needs
4
+ WORKDIR /app
5
+
6
+ # Install Python deps first (better layer caching)
7
+ COPY requirements.txt .
8
+ RUN pip install --no-cache-dir -r requirements.txt
9
+
10
+ # Copy the rest of your code
11
+ COPY . .
12
+
13
+ # Start the server. HF injects $PORT; our main.py reads it.
14
+ CMD ["python", "main.py"]
15
+
main.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # main.py
2
+ import os
3
+ import uvicorn
4
+
5
+ # ---- Adjust imports to match a2a-python ----
6
+ # These paths are common in the tutorial; if yours differ, change them accordingly.
7
+ from a2a.server.apps import A2AStarletteApplication
8
+ from a2a.server.request_handlers import DefaultRequestHandler
9
+ from a2a.server.tasks import InMemoryTaskStore
10
+
11
+ # Example minimal executor
12
+ class HelloWorldAgentExecutor:
13
+ async def call(self, message: str, **kwargs):
14
+ return {"text": f"Hello from A2A on HF Spaces! You said: {message}"}
15
+
16
+ # Example minimal public AgentCard (adjust fields to your spec)
17
+ AGENT_CARD = {
18
+ "name": "HF A2A Agent",
19
+ "version": "1.0",
20
+ "description": "A2A demo running on Hugging Face Spaces",
21
+ "endpoints": {
22
+ "send": "/message/send",
23
+ "stream": "/message/stream"
24
+ }
25
+ }
26
+
27
+ def build_app():
28
+ app = A2AStarletteApplication(
29
+ agent_card=AGENT_CARD,
30
+ http_handler=DefaultRequestHandler(
31
+ agent_executor=HelloWorldAgentExecutor(),
32
+ task_store=InMemoryTaskStore(),
33
+ ),
34
+ # extended_agent_card=... # optional
35
+ ).build()
36
+ return app
37
+
38
+ if __name__ == "__main__":
39
+ port = int(os.getenv("PORT", "7860")) # HF provides PORT
40
+ uvicorn.run(build_app(), host="0.0.0.0", port=port)
41
+
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ uvicorn>=0.30
2
+ starlette>=0.37
3
+ # The A2A library (adjust to the name/extra you use)
4
+ a2a-python