|
7 | 7 |
|
8 | 8 | """A2A HTTP server for Oracle Database AI Agent Teams.""" |
9 | 9 |
|
| 10 | +import json |
10 | 11 | from contextlib import asynccontextmanager |
11 | 12 | from typing import Optional |
12 | 13 |
|
13 | 14 | from a2a.compat.v0_3.conversions import to_compat_agent_card |
14 | | -from a2a.helpers import new_task_from_user_message, new_text_part |
| 15 | +from a2a.helpers import ( |
| 16 | + new_data_part, |
| 17 | + new_task_from_user_message, |
| 18 | + new_text_part, |
| 19 | +) |
15 | 20 | from a2a.server.agent_execution import AgentExecutor |
16 | 21 | from a2a.server.request_handlers import DefaultRequestHandler |
17 | 22 | from a2a.server.routes import create_jsonrpc_routes |
|
27 | 32 | from select_ai.agent.a2a.task_store import OracleTaskStore |
28 | 33 | from select_ai.version import __version__ |
29 | 34 |
|
| 35 | +_A2UI_MIME_TYPE = "application/a2ui+json" |
| 36 | + |
| 37 | + |
| 38 | +def _a2ui_payload(result: str | None) -> dict | None: |
| 39 | + """Return an A2UI response envelope, if ``RUN_TEAM`` returned one.""" |
| 40 | + if not result: |
| 41 | + return None |
| 42 | + try: |
| 43 | + payload = json.loads(result) |
| 44 | + except json.JSONDecodeError: |
| 45 | + return None |
| 46 | + if not isinstance(payload, dict): |
| 47 | + return None |
| 48 | + if payload.get("metadata", {}).get("mimeType") != _A2UI_MIME_TYPE: |
| 49 | + return None |
| 50 | + if not isinstance(payload.get("data"), list): |
| 51 | + return None |
| 52 | + return payload |
| 53 | + |
30 | 54 |
|
31 | 55 | class DatabaseTeamExecutor(AgentExecutor): |
32 | 56 | """Execute A2A requests with one Oracle conversation per A2A context.""" |
@@ -57,8 +81,13 @@ async def execute(self, context, event_queue): |
57 | 81 | prompt=context.get_user_input(), |
58 | 82 | params={"conversation_id": conversation_id}, |
59 | 83 | ) |
| 84 | + a2ui_payload = _a2ui_payload(result) |
60 | 85 | await updater.add_artifact( |
61 | | - parts=[new_text_part(result or "")], |
| 86 | + parts=( |
| 87 | + [new_data_part(a2ui_payload)] |
| 88 | + if a2ui_payload is not None |
| 89 | + else [new_text_part(result or "")] |
| 90 | + ), |
62 | 91 | name="database-agent-result", |
63 | 92 | last_chunk=True, |
64 | 93 | ) |
|
0 commit comments