agent-framework-hosting-a2a 1.0.0a260721__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- agent_framework_hosting_a2a-1.0.0a260721/LICENSE +21 -0
- agent_framework_hosting_a2a-1.0.0a260721/PKG-INFO +65 -0
- agent_framework_hosting_a2a-1.0.0a260721/README.md +38 -0
- agent_framework_hosting_a2a-1.0.0a260721/agent_framework_hosting_a2a/__init__.py +18 -0
- agent_framework_hosting_a2a-1.0.0a260721/agent_framework_hosting_a2a/_conversion.py +158 -0
- agent_framework_hosting_a2a-1.0.0a260721/agent_framework_hosting_a2a/py.typed +0 -0
- agent_framework_hosting_a2a-1.0.0a260721/pyproject.toml +80 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agent-framework-hosting-a2a
|
|
3
|
+
Version: 1.0.0a260721
|
|
4
|
+
Summary: A2A conversion helpers for app-owned Agent Framework hosting.
|
|
5
|
+
Author-email: Microsoft <af-support@microsoft.com>
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
9
|
+
Classifier: Development Status :: 3 - Alpha
|
|
10
|
+
Classifier: Intended Audience :: Developers
|
|
11
|
+
Classifier: Programming Language :: Python :: 3
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
License-File: LICENSE
|
|
19
|
+
Requires-Dist: a2a-sdk>=1.0.0,<2
|
|
20
|
+
Requires-Dist: agent-framework-core>=1.11.0,<2
|
|
21
|
+
Requires-Dist: agent-framework-hosting==1.0.0a260721
|
|
22
|
+
Project-URL: homepage, https://aka.ms/agent-framework
|
|
23
|
+
Project-URL: issues, https://github.com/microsoft/agent-framework/issues
|
|
24
|
+
Project-URL: release_notes, https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true
|
|
25
|
+
Project-URL: source, https://github.com/microsoft/agent-framework/tree/main/python
|
|
26
|
+
|
|
27
|
+
# agent-framework-hosting-a2a
|
|
28
|
+
|
|
29
|
+
A2A conversion helpers for app-owned Agent Framework hosting.
|
|
30
|
+
|
|
31
|
+
The package deliberately does not choose a web framework or wrap the A2A SDK
|
|
32
|
+
server lifecycle. It provides two conversion functions:
|
|
33
|
+
|
|
34
|
+
- `a2a_to_run(...)` converts a native A2A `Message` into Agent Framework run
|
|
35
|
+
arguments.
|
|
36
|
+
- `a2a_from_run(...)` converts an `AgentResponse`, `Message`, or streaming
|
|
37
|
+
`AgentResponseUpdate` into native A2A `Part` values.
|
|
38
|
+
|
|
39
|
+
Application code keeps ownership of the A2A SDK's `AgentExecutor`,
|
|
40
|
+
`RequestContext`, `TaskUpdater`, event queue, task store, routes, task state,
|
|
41
|
+
artifact IDs, authentication, and deployment.
|
|
42
|
+
|
|
43
|
+
`a2a_from_run(...)` preserves content-level metadata on each returned part and
|
|
44
|
+
flattens completed responses in message order. The application decides how to
|
|
45
|
+
group those parts into A2A messages or artifacts and owns their message-level
|
|
46
|
+
metadata and boundaries.
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
run = a2a_to_run(context.message)
|
|
50
|
+
session_id = f"a2a:{context.tenant}:{context.context_id}"
|
|
51
|
+
session = await state.get_or_create_session(session_id)
|
|
52
|
+
result = await agent.run(
|
|
53
|
+
run["messages"],
|
|
54
|
+
session=session,
|
|
55
|
+
options=run["options"],
|
|
56
|
+
)
|
|
57
|
+
await state.set_session(session_id, session)
|
|
58
|
+
parts = a2a_from_run(result)
|
|
59
|
+
|
|
60
|
+
# Native A2A SDK application code publishes `parts` with TaskUpdater.
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
The surrounding A2A application may use Starlette, FastAPI, another ASGI
|
|
64
|
+
framework, or the SDK's own application builders. These helpers do not care.
|
|
65
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# agent-framework-hosting-a2a
|
|
2
|
+
|
|
3
|
+
A2A conversion helpers for app-owned Agent Framework hosting.
|
|
4
|
+
|
|
5
|
+
The package deliberately does not choose a web framework or wrap the A2A SDK
|
|
6
|
+
server lifecycle. It provides two conversion functions:
|
|
7
|
+
|
|
8
|
+
- `a2a_to_run(...)` converts a native A2A `Message` into Agent Framework run
|
|
9
|
+
arguments.
|
|
10
|
+
- `a2a_from_run(...)` converts an `AgentResponse`, `Message`, or streaming
|
|
11
|
+
`AgentResponseUpdate` into native A2A `Part` values.
|
|
12
|
+
|
|
13
|
+
Application code keeps ownership of the A2A SDK's `AgentExecutor`,
|
|
14
|
+
`RequestContext`, `TaskUpdater`, event queue, task store, routes, task state,
|
|
15
|
+
artifact IDs, authentication, and deployment.
|
|
16
|
+
|
|
17
|
+
`a2a_from_run(...)` preserves content-level metadata on each returned part and
|
|
18
|
+
flattens completed responses in message order. The application decides how to
|
|
19
|
+
group those parts into A2A messages or artifacts and owns their message-level
|
|
20
|
+
metadata and boundaries.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
run = a2a_to_run(context.message)
|
|
24
|
+
session_id = f"a2a:{context.tenant}:{context.context_id}"
|
|
25
|
+
session = await state.get_or_create_session(session_id)
|
|
26
|
+
result = await agent.run(
|
|
27
|
+
run["messages"],
|
|
28
|
+
session=session,
|
|
29
|
+
options=run["options"],
|
|
30
|
+
)
|
|
31
|
+
await state.set_session(session_id, session)
|
|
32
|
+
parts = a2a_from_run(result)
|
|
33
|
+
|
|
34
|
+
# Native A2A SDK application code publishes `parts` with TaskUpdater.
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The surrounding A2A application may use Starlette, FastAPI, another ASGI
|
|
38
|
+
framework, or the SDK's own application builders. These helpers do not care.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""A2A conversion helpers for app-owned Agent Framework hosting."""
|
|
4
|
+
|
|
5
|
+
import importlib.metadata
|
|
6
|
+
|
|
7
|
+
from ._conversion import a2a_from_run, a2a_to_run
|
|
8
|
+
|
|
9
|
+
try:
|
|
10
|
+
__version__ = importlib.metadata.version(__name__)
|
|
11
|
+
except importlib.metadata.PackageNotFoundError:
|
|
12
|
+
__version__ = "0.0.0"
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"__version__",
|
|
16
|
+
"a2a_from_run",
|
|
17
|
+
"a2a_to_run",
|
|
18
|
+
]
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
# Copyright (c) Microsoft. All rights reserved.
|
|
2
|
+
|
|
3
|
+
"""Conversion between native A2A values and Agent Framework run values."""
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
import base64
|
|
8
|
+
import json
|
|
9
|
+
import logging
|
|
10
|
+
from collections.abc import Sequence
|
|
11
|
+
from typing import Any, cast
|
|
12
|
+
|
|
13
|
+
from a2a.types import Message as A2AMessage
|
|
14
|
+
from a2a.types import Part
|
|
15
|
+
from agent_framework import AgentResponse, AgentResponseUpdate, ChatOptions, Content, Message
|
|
16
|
+
from agent_framework_hosting import AgentRunArgs
|
|
17
|
+
from google.protobuf.json_format import MessageToDict
|
|
18
|
+
|
|
19
|
+
logger = logging.getLogger("agent_framework.hosting.a2a")
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def a2a_to_run(message: A2AMessage, *, stream: bool = False) -> AgentRunArgs:
|
|
23
|
+
"""Convert an A2A message into Agent Framework run arguments.
|
|
24
|
+
|
|
25
|
+
A2A text, URL, raw-byte, and structured-data parts become Agent Framework
|
|
26
|
+
content. The helper does not create sessions, inspect task stores, or
|
|
27
|
+
interact with an A2A request handler.
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
message: Native A2A message to convert.
|
|
31
|
+
|
|
32
|
+
Keyword Args:
|
|
33
|
+
stream: Whether the caller intends to run the agent in streaming mode.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
Arguments corresponding to ``Agent.run(...)``.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
ValueError: If the message has no supported content parts.
|
|
40
|
+
"""
|
|
41
|
+
contents: list[Content] = []
|
|
42
|
+
for part in message.parts:
|
|
43
|
+
metadata = MessageToDict(part.metadata) if part.metadata else None
|
|
44
|
+
match part.WhichOneof("content"):
|
|
45
|
+
case "text":
|
|
46
|
+
contents.append(
|
|
47
|
+
Content.from_text(
|
|
48
|
+
text=part.text,
|
|
49
|
+
additional_properties=metadata,
|
|
50
|
+
raw_representation=part,
|
|
51
|
+
)
|
|
52
|
+
)
|
|
53
|
+
case "url":
|
|
54
|
+
contents.append(
|
|
55
|
+
Content.from_uri(
|
|
56
|
+
uri=part.url,
|
|
57
|
+
media_type=part.media_type or None,
|
|
58
|
+
additional_properties=metadata,
|
|
59
|
+
raw_representation=part,
|
|
60
|
+
)
|
|
61
|
+
)
|
|
62
|
+
case "raw":
|
|
63
|
+
contents.append(
|
|
64
|
+
Content.from_data(
|
|
65
|
+
data=part.raw,
|
|
66
|
+
media_type=part.media_type or "application/octet-stream",
|
|
67
|
+
additional_properties=metadata,
|
|
68
|
+
raw_representation=part,
|
|
69
|
+
)
|
|
70
|
+
)
|
|
71
|
+
case "data":
|
|
72
|
+
contents.append(
|
|
73
|
+
Content.from_text(
|
|
74
|
+
text=json.dumps(MessageToDict(part.data), separators=(",", ":"), sort_keys=True),
|
|
75
|
+
additional_properties=metadata,
|
|
76
|
+
raw_representation=part,
|
|
77
|
+
)
|
|
78
|
+
)
|
|
79
|
+
case unsupported:
|
|
80
|
+
logger.warning("A2A message part type %s is not supported and was omitted.", unsupported)
|
|
81
|
+
|
|
82
|
+
if not contents:
|
|
83
|
+
raise ValueError("A2A message has no supported text, URL, raw, or data parts to convert to a run.")
|
|
84
|
+
|
|
85
|
+
return AgentRunArgs(
|
|
86
|
+
messages=[
|
|
87
|
+
Message(
|
|
88
|
+
"user",
|
|
89
|
+
contents,
|
|
90
|
+
message_id=message.message_id or None,
|
|
91
|
+
additional_properties={"a2a_metadata": MessageToDict(message.metadata)} if message.metadata else None,
|
|
92
|
+
raw_representation=message,
|
|
93
|
+
)
|
|
94
|
+
],
|
|
95
|
+
options=cast("ChatOptions[Any]", {}),
|
|
96
|
+
stream=stream,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def a2a_from_run(result: AgentResponse[Any] | Message | AgentResponseUpdate) -> list[Part]:
|
|
101
|
+
"""Convert Agent Framework output into native A2A parts.
|
|
102
|
+
|
|
103
|
+
``AgentResponse`` values are flattened in message order. User-role
|
|
104
|
+
messages are omitted. Text, external URI, and inline data content become
|
|
105
|
+
the corresponding native A2A part types. Content-level metadata is
|
|
106
|
+
preserved on each part. The caller remains responsible for grouping parts
|
|
107
|
+
into A2A messages or artifacts, including message boundaries and metadata,
|
|
108
|
+
and publishing them through ``TaskUpdater`` or an event queue.
|
|
109
|
+
|
|
110
|
+
Args:
|
|
111
|
+
result: A completed response, response message, or streaming update.
|
|
112
|
+
|
|
113
|
+
Returns:
|
|
114
|
+
Native A2A parts ready for an A2A SDK message or artifact.
|
|
115
|
+
|
|
116
|
+
Raises:
|
|
117
|
+
ValueError: If Agent Framework data content contains an invalid data URI.
|
|
118
|
+
"""
|
|
119
|
+
items: Sequence[Message | AgentResponseUpdate] = result.messages if isinstance(result, AgentResponse) else [result]
|
|
120
|
+
|
|
121
|
+
parts: list[Part] = []
|
|
122
|
+
for item in items:
|
|
123
|
+
if item.role == "user":
|
|
124
|
+
continue
|
|
125
|
+
for content in item.contents:
|
|
126
|
+
metadata = content.additional_properties or {}
|
|
127
|
+
match content.type:
|
|
128
|
+
case "text" if content.text is not None:
|
|
129
|
+
parts.append(Part(text=content.text, metadata=metadata))
|
|
130
|
+
case "uri" if content.uri is not None:
|
|
131
|
+
parts.append(
|
|
132
|
+
Part(
|
|
133
|
+
url=content.uri,
|
|
134
|
+
media_type=content.media_type or "",
|
|
135
|
+
metadata=metadata,
|
|
136
|
+
)
|
|
137
|
+
)
|
|
138
|
+
case "data" if content.uri is not None:
|
|
139
|
+
prefix, separator, encoded = content.uri.partition(",")
|
|
140
|
+
if not separator or not prefix.startswith("data:") or ";base64" not in prefix:
|
|
141
|
+
raise ValueError("Agent Framework data content must contain a base64 data URI.")
|
|
142
|
+
try:
|
|
143
|
+
raw = base64.b64decode(encoded, validate=True)
|
|
144
|
+
except ValueError as exc:
|
|
145
|
+
raise ValueError("Agent Framework data content contains invalid base64 data.") from exc
|
|
146
|
+
parts.append(
|
|
147
|
+
Part(
|
|
148
|
+
raw=raw,
|
|
149
|
+
media_type=content.media_type or "",
|
|
150
|
+
metadata=metadata,
|
|
151
|
+
)
|
|
152
|
+
)
|
|
153
|
+
case _:
|
|
154
|
+
logger.warning(
|
|
155
|
+
"Agent Framework content type %s is not supported by A2A and was omitted.",
|
|
156
|
+
content.type,
|
|
157
|
+
)
|
|
158
|
+
return parts
|
|
File without changes
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "agent-framework-hosting-a2a"
|
|
3
|
+
description = "A2A conversion helpers for app-owned Agent Framework hosting."
|
|
4
|
+
authors = [{ name = "Microsoft", email = "af-support@microsoft.com"}]
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
version = "1.0.0a260721"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
urls.homepage = "https://aka.ms/agent-framework"
|
|
10
|
+
urls.source = "https://github.com/microsoft/agent-framework/tree/main/python"
|
|
11
|
+
urls.release_notes = "https://github.com/microsoft/agent-framework/releases?q=tag%3Apython-1&expanded=true"
|
|
12
|
+
urls.issues = "https://github.com/microsoft/agent-framework/issues"
|
|
13
|
+
classifiers = [
|
|
14
|
+
"License :: OSI Approved :: MIT License",
|
|
15
|
+
"Development Status :: 3 - Alpha",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"Programming Language :: Python :: 3.10",
|
|
19
|
+
"Programming Language :: Python :: 3.11",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Programming Language :: Python :: 3.14",
|
|
23
|
+
"Typing :: Typed",
|
|
24
|
+
]
|
|
25
|
+
dependencies = [
|
|
26
|
+
"a2a-sdk>=1.0.0,<2",
|
|
27
|
+
"agent-framework-core>=1.11.0,<2",
|
|
28
|
+
"agent-framework-hosting==1.0.0a260721",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[tool.uv]
|
|
32
|
+
prerelease = "if-necessary-or-explicit"
|
|
33
|
+
environments = [
|
|
34
|
+
"sys_platform == 'darwin'",
|
|
35
|
+
"sys_platform == 'linux'",
|
|
36
|
+
"sys_platform == 'win32'"
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
[tool.uv-dynamic-versioning]
|
|
40
|
+
fallback-version = "0.0.0"
|
|
41
|
+
|
|
42
|
+
[tool.pytest.ini_options]
|
|
43
|
+
testpaths = 'tests'
|
|
44
|
+
addopts = "-ra -q -r fEX"
|
|
45
|
+
asyncio_mode = "auto"
|
|
46
|
+
asyncio_default_fixture_loop_scope = "function"
|
|
47
|
+
filterwarnings = []
|
|
48
|
+
timeout = 120
|
|
49
|
+
markers = [
|
|
50
|
+
"integration: marks tests as integration tests that require external services",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[tool.ruff]
|
|
54
|
+
extend = "../../pyproject.toml"
|
|
55
|
+
|
|
56
|
+
[tool.coverage.run]
|
|
57
|
+
omit = [
|
|
58
|
+
"**/__init__.py"
|
|
59
|
+
]
|
|
60
|
+
|
|
61
|
+
[tool.pyright]
|
|
62
|
+
extends = "../../pyproject.toml"
|
|
63
|
+
include = ["agent_framework_hosting_a2a"]
|
|
64
|
+
exclude = ['tests']
|
|
65
|
+
|
|
66
|
+
[tool.bandit]
|
|
67
|
+
targets = ["agent_framework_hosting_a2a"]
|
|
68
|
+
exclude_dirs = ["tests"]
|
|
69
|
+
|
|
70
|
+
[tool.poe]
|
|
71
|
+
executor.type = "uv"
|
|
72
|
+
include = "../../shared_tasks.toml"
|
|
73
|
+
|
|
74
|
+
[tool.poe.tasks.test]
|
|
75
|
+
help = "Run the default unit test suite for this package."
|
|
76
|
+
cmd = 'pytest -m "not integration" --cov=agent_framework_hosting_a2a --cov-report=term-missing:skip-covered tests'
|
|
77
|
+
|
|
78
|
+
[build-system]
|
|
79
|
+
requires = ["flit-core >= 3.11,<4.0"]
|
|
80
|
+
build-backend = "flit_core.buildapi"
|