Skip to content

Commit 3bcba7d

Browse files
committed
fixing ignored history lenght in task/get
1 parent 299e281 commit 3bcba7d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/a2a/server/request_handlers/default_request_handler.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,26 @@ async def on_get_task(
112112
task: Task | None = await self.task_store.get(params.id)
113113
if not task:
114114
raise ServerError(error=TaskNotFoundError())
115+
116+
# Apply historyLength parameter if specified
117+
if params.history_length is not None and task.history:
118+
# Limit history to the most recent N messages
119+
limited_history = (
120+
task.history[-params.history_length :]
121+
if params.history_length > 0
122+
else []
123+
)
124+
# Create a new task instance with limited history
125+
task = Task(
126+
id=task.id,
127+
context_id=task.context_id,
128+
status=task.status,
129+
artifacts=task.artifacts,
130+
history=limited_history,
131+
metadata=task.metadata,
132+
kind=task.kind,
133+
)
134+
115135
return task
116136

117137
async def on_cancel_task(

0 commit comments

Comments
 (0)