Skip to content

Commit dab3656

Browse files
authored
Merge branch 'main' into docs/add-new-example-mcp-without-llm-framework
2 parents 9bf0aca + a9781b5 commit dab3656

File tree

16 files changed

+1526
-355
lines changed

16 files changed

+1526
-355
lines changed

.github/actions/spelling/allow.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ dunders
2626
genai
2727
gle
2828
inmemory
29+
kwarg
2930
langgraph
3031
lifecycles
3132
linting

.github/linters/.markdownlint.json

Lines changed: 0 additions & 4 deletions
This file was deleted.

.github/release-please.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
releaseType: python
22
handleGHRelease: true
33
bumpMinorPreMajor: false
4+
bumpPatchForMinorPreMajor: true

.github/workflows/linter.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,5 @@ jobs:
6262
VALIDATE_JAVASCRIPT_STANDARD: false
6363
VALIDATE_TYPESCRIPT_STANDARD: false
6464
VALIDATE_GIT_COMMITLINT: false
65-
MARKDOWN_CONFIG_FILE: .markdownlint.json
6665
PYTHON_MYPY_CONFIG_FILE: .mypy.ini
67-
FILTER_REGEX_EXCLUDE: "^examples/.*$|^CHANGELOG\\.md$"
66+
FILTER_REGEX_INCLUDE: "^src/**"

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
## [0.2.3](https://github.com/google/a2a-python/compare/v0.2.2...v0.2.3) (2025-05-20)
4+
5+
6+
### Features
7+
8+
* Add request context builder with referenceTasks ([#56](https://github.com/google/a2a-python/issues/56)) ([f20bfe7](https://github.com/google/a2a-python/commit/f20bfe74b8cc854c9c29720b2ea3859aff8f509e))
9+
10+
## [0.2.2](https://github.com/google/a2a-python/compare/v0.2.1...v0.2.2) (2025-05-20)
11+
12+
13+
### Documentation
14+
15+
* Write/Update Docstrings for Classes/Methods ([#59](https://github.com/google/a2a-python/issues/59)) ([9f773ef](https://github.com/google/a2a-python/commit/9f773eff4dddc4eec723d519d0050f21b9ccc042))

development.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,20 @@
22

33
## Type generation from spec
44

5-
<!-- TODO replace spec.json with the public url so we always get the latest version-->
6-
75
```bash
8-
uv run datamodel-codegen --input ./spec.json --input-file-type jsonschema --output ./src/a2a/types.py --target-python-version 3.10 --output-model-type pydantic_v2.BaseModel --disable-timestamp --use-schema-description --use-union-operator --use-field-description --use-default --use-default-kwarg --use-one-literal-as-default --class-name A2A --use-standard-collections
6+
uv run datamodel-codegen \
7+
--url https://raw.githubusercontent.com/google/A2A/refs/heads/main/specification/json/a2a.json \
8+
--input-file-type jsonschema \
9+
--output ./src/a2a/types.py \
10+
--target-python-version 3.10 \
11+
--output-model-type pydantic_v2.BaseModel \
12+
--disable-timestamp \
13+
--use-schema-description \
14+
--use-union-operator \
15+
--use-field-description \
16+
--use-default \
17+
--use-default-kwarg \
18+
--use-one-literal-as-default \
19+
--class-name A2A \
20+
--use-standard-collections
921
```

examples/langgraph/agent_executor.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from agent import CurrencyAgent # type: ignore[import-untyped]
2-
from typing_extensions import override
1+
from agent import CurrencyAgent # type: ignore[import-untyped]
2+
33
from a2a.server.agent_execution import AgentExecutor, RequestContext
44
from a2a.server.events.event_queue import EventQueue
55
from a2a.types import (
@@ -17,7 +17,6 @@ class CurrencyAgentExecutor(AgentExecutor):
1717
def __init__(self):
1818
self.agent = CurrencyAgent()
1919

20-
@override
2120
async def execute(
2221
self,
2322
context: RequestContext,
@@ -89,7 +88,6 @@ async def execute(
8988
)
9089
)
9190

92-
@override
9391
async def cancel(
9492
self, context: RequestContext, event_queue: EventQueue
9593
) -> None:

src/a2a/server/agent_execution/__init__.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,17 @@
22

33
from a2a.server.agent_execution.agent_executor import AgentExecutor
44
from a2a.server.agent_execution.context import RequestContext
5+
from a2a.server.agent_execution.request_context_builder import (
6+
RequestContextBuilder,
7+
)
8+
from a2a.server.agent_execution.simple_request_context_builder import (
9+
SimpleRequestContextBuilder,
10+
)
511

612

7-
__all__ = ['AgentExecutor', 'RequestContext']
13+
__all__ = [
14+
'AgentExecutor',
15+
'RequestContext',
16+
'RequestContextBuilder',
17+
'SimpleRequestContextBuilder',
18+
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from abc import ABC, abstractmethod
2+
3+
from a2a.server.agent_execution import RequestContext
4+
from a2a.types import MessageSendParams, Task
5+
6+
7+
class RequestContextBuilder(ABC):
8+
"""Builds request context to be supplied to agent executor"""
9+
10+
@abstractmethod
11+
async def build(
12+
self,
13+
params: MessageSendParams | None = None,
14+
task_id: str | None = None,
15+
context_id: str | None = None,
16+
task: Task | None = None,
17+
) -> RequestContext:
18+
pass
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import asyncio
2+
3+
from a2a.server.agent_execution import RequestContext, RequestContextBuilder
4+
from a2a.server.tasks import TaskStore
5+
from a2a.types import MessageSendParams, Task
6+
7+
8+
class SimpleRequestContextBuilder(RequestContextBuilder):
9+
"""Builds request context and populates referred tasks"""
10+
11+
def __init__(
12+
self,
13+
should_populate_referred_tasks: bool = False,
14+
task_store: TaskStore | None = None,
15+
) -> None:
16+
self._task_store = task_store
17+
self._should_populate_referred_tasks = should_populate_referred_tasks
18+
19+
async def build(
20+
self,
21+
params: MessageSendParams | None = None,
22+
task_id: str | None = None,
23+
context_id: str | None = None,
24+
task: Task | None = None,
25+
) -> RequestContext:
26+
related_tasks: list[Task] | None = None
27+
28+
if (
29+
self._task_store
30+
and self._should_populate_referred_tasks
31+
and params
32+
and params.message.referenceTaskIds
33+
):
34+
tasks = await asyncio.gather(
35+
*[
36+
self._task_store.get(task_id)
37+
for task_id in params.message.referenceTaskIds
38+
]
39+
)
40+
related_tasks = [x for x in tasks if x is not None]
41+
42+
return RequestContext(
43+
request=params,
44+
task_id=task_id,
45+
context_id=context_id,
46+
task=task,
47+
related_tasks=related_tasks,
48+
)

0 commit comments

Comments
 (0)