Spaces:
Sleeping
Sleeping
Sheyda Kiani Mehr
commited on
Commit
·
026a6f0
1
Parent(s):
d98558a
fix on object
Browse files
main.py
CHANGED
|
@@ -2,40 +2,60 @@
|
|
| 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 |
-
#
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
| 29 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
http_handler=DefaultRequestHandler(
|
| 31 |
agent_executor=HelloWorldAgentExecutor(),
|
| 32 |
task_store=InMemoryTaskStore(),
|
| 33 |
),
|
| 34 |
-
# extended_agent_card=... #
|
| 35 |
-
)
|
| 36 |
-
return
|
| 37 |
|
| 38 |
if __name__ == "__main__":
|
| 39 |
-
port = int(os.getenv("PORT", "7860"))
|
| 40 |
uvicorn.run(build_app(), host="0.0.0.0", port=port)
|
| 41 |
-
|
|
|
|
| 2 |
import os
|
| 3 |
import uvicorn
|
| 4 |
|
|
|
|
|
|
|
| 5 |
from a2a.server.apps import A2AStarletteApplication
|
| 6 |
from a2a.server.request_handlers import DefaultRequestHandler
|
| 7 |
from a2a.server.tasks import InMemoryTaskStore
|
| 8 |
|
| 9 |
+
# use the typed models from the SDK
|
| 10 |
+
from a2a.types import AgentCard, AgentCapabilities, AgentSkill
|
| 11 |
+
|
| 12 |
+
# Minimal executor
|
| 13 |
class HelloWorldAgentExecutor:
|
| 14 |
async def call(self, message: str, **kwargs):
|
| 15 |
return {"text": f"Hello from A2A on HF Spaces! You said: {message}"}
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
def build_app():
|
| 18 |
+
# Define at least one skill (IDs are free-form but should be stable)
|
| 19 |
+
hello_skill = AgentSkill(
|
| 20 |
+
id="hello",
|
| 21 |
+
name="Say Hello",
|
| 22 |
+
description="Return a friendly greeting",
|
| 23 |
+
tags=["hello", "demo"],
|
| 24 |
+
examples=["hi", "hello there"],
|
| 25 |
+
)
|
| 26 |
+
|
| 27 |
+
# HF Spaces gives you a PORT; URL here is informational for clients
|
| 28 |
+
public_url = os.getenv("SPACE_HOST") # e.g. "username-space.hf.space"
|
| 29 |
+
if public_url:
|
| 30 |
+
public_url = f"https://{public_url}/"
|
| 31 |
+
else:
|
| 32 |
+
# local/dev fallback
|
| 33 |
+
public_url = f"http://0.0.0.0:{os.getenv('PORT', '7860')}/"
|
| 34 |
+
|
| 35 |
+
agent_card = AgentCard(
|
| 36 |
+
name="HF A2A Agent",
|
| 37 |
+
description="A2A demo running on Hugging Face Spaces",
|
| 38 |
+
version="1.0.0",
|
| 39 |
+
url=public_url,
|
| 40 |
+
protocol_version="0.3.0",
|
| 41 |
+
default_input_modes=["text"],
|
| 42 |
+
default_output_modes=["text"],
|
| 43 |
+
capabilities=AgentCapabilities(streaming=False),
|
| 44 |
+
skills=[hello_skill],
|
| 45 |
+
# keep it simple: no authenticated extended card for now
|
| 46 |
+
supports_authenticated_extended_card=False,
|
| 47 |
+
)
|
| 48 |
+
|
| 49 |
+
app_builder = A2AStarletteApplication(
|
| 50 |
+
agent_card=agent_card,
|
| 51 |
http_handler=DefaultRequestHandler(
|
| 52 |
agent_executor=HelloWorldAgentExecutor(),
|
| 53 |
task_store=InMemoryTaskStore(),
|
| 54 |
),
|
| 55 |
+
# extended_agent_card=... # only if you actually support it
|
| 56 |
+
)
|
| 57 |
+
return app_builder.build()
|
| 58 |
|
| 59 |
if __name__ == "__main__":
|
| 60 |
+
port = int(os.getenv("PORT", "7860"))
|
| 61 |
uvicorn.run(build_app(), host="0.0.0.0", port=port)
|
|
|