Spaces:
Running
Running
abrakjamson
commited on
Commit
·
d37bc24
1
Parent(s):
ebdde3c
converted to json-rpc
Browse files- __pycache__/task_management.cpython-310.pyc +0 -0
- app.py +1 -1
- requirements.txt +1 -1
- task_management.py +16 -15
__pycache__/task_management.cpython-310.pyc
CHANGED
Binary files a/__pycache__/task_management.cpython-310.pyc and b/__pycache__/task_management.cpython-310.pyc differ
|
|
app.py
CHANGED
@@ -19,7 +19,7 @@ def fetch_agent_card(url: str) -> dict:
|
|
19 |
url = url[:-1]
|
20 |
agent_card_url = f"{url}/.well-known/agent.json"
|
21 |
try:
|
22 |
-
resp = requests.get(agent_card_url, timeout=
|
23 |
resp.raise_for_status()
|
24 |
agent_card = resp.json()
|
25 |
return agent_card
|
|
|
19 |
url = url[:-1]
|
20 |
agent_card_url = f"{url}/.well-known/agent.json"
|
21 |
try:
|
22 |
+
resp = requests.get(agent_card_url, timeout=15)
|
23 |
resp.raise_for_status()
|
24 |
agent_card = resp.json()
|
25 |
return agent_card
|
requirements.txt
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
gradio==5.29
|
2 |
requests
|
3 |
pydantic==2.10.6
|
4 |
google-genai==1.5.0
|
|
|
1 |
+
gradio==5.29
|
2 |
requests
|
3 |
pydantic==2.10.6
|
4 |
google-genai==1.5.0
|
task_management.py
CHANGED
@@ -6,13 +6,17 @@ def send_task(server_url, task_id, thread, content):
|
|
6 |
"jsonrpc": "2.0",
|
7 |
"method": "tasks/send",
|
8 |
"params": {
|
9 |
-
"
|
10 |
-
"
|
11 |
-
"content": content
|
12 |
},
|
13 |
"id": task_id
|
14 |
}
|
15 |
-
|
|
|
|
|
|
|
|
|
|
|
16 |
return response.json()
|
17 |
|
18 |
def get_task_status(server_url, task_id):
|
@@ -58,22 +62,19 @@ def a2a_respond(user_message, history, server_url):
|
|
58 |
return "", history
|
59 |
|
60 |
session_id = str(uuid.uuid4())
|
61 |
-
request_body = {
|
62 |
-
"user_input": user_message,
|
63 |
-
"session_id": session_id
|
64 |
-
}
|
65 |
|
66 |
history = history or []
|
67 |
history.append({"role": "user", "content": user_message})
|
68 |
|
69 |
try:
|
70 |
-
#
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
|
|
77 |
if agent_reply:
|
78 |
history.append({"role": "assistant", "content": agent_reply})
|
79 |
except Exception as e:
|
|
|
6 |
"jsonrpc": "2.0",
|
7 |
"method": "tasks/send",
|
8 |
"params": {
|
9 |
+
"sessionId": thread,
|
10 |
+
"message": content
|
|
|
11 |
},
|
12 |
"id": task_id
|
13 |
}
|
14 |
+
#remove trailing slash if present
|
15 |
+
if server_url.endswith("/"):
|
16 |
+
server_url = server_url[:-1]
|
17 |
+
json_endpoint = f"{server_url}/jsonrpc"
|
18 |
+
response = requests.post(json_endpoint, json=payload)
|
19 |
+
response.raise_for_status()
|
20 |
return response.json()
|
21 |
|
22 |
def get_task_status(server_url, task_id):
|
|
|
62 |
return "", history
|
63 |
|
64 |
session_id = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
65 |
|
66 |
history = history or []
|
67 |
history.append({"role": "user", "content": user_message})
|
68 |
|
69 |
try:
|
70 |
+
# Call send_task with the server_url and session_id
|
71 |
+
response = send_task(server_url, session_id, "thread", user_message)
|
72 |
+
if response.get("error"):
|
73 |
+
error_message = response["error"].get("message", "Unknown error")
|
74 |
+
history.append({"role": "assistant", "content": f"Error: {error_message}"})
|
75 |
+
return "", history
|
76 |
+
# get the result.content from the json
|
77 |
+
agent_reply = response.get("result", {}).get("content", "")
|
78 |
if agent_reply:
|
79 |
history.append({"role": "assistant", "content": agent_reply})
|
80 |
except Exception as e:
|