@@ -127,27 +127,27 @@ def update_api_key(self, api_key: str):
127
127
self ._task_map = {}
128
128
129
129
def sanitize_message (self , message : Message ) -> Message :
130
- if message .contextId :
131
- conversation = self .get_conversation (message .contextId )
130
+ if message .context_id :
131
+ conversation = self .get_conversation (message .context_id )
132
132
if not conversation :
133
133
return message
134
134
# Check if the last event in the conversation was tied to a task.
135
135
if conversation .messages :
136
- task_id = conversation .messages [- 1 ].taskId
136
+ task_id = conversation .messages [- 1 ].task_id
137
137
if task_id and task_still_open (
138
138
next (
139
139
filter (lambda x : x and x .id == task_id , self ._tasks ),
140
140
None ,
141
141
)
142
142
):
143
- message .taskId = task_id
143
+ message .task_id = task_id
144
144
return message
145
145
146
146
async def process_message (self , message : Message ):
147
- message_id = message .messageId
147
+ message_id = message .message_id
148
148
if message_id :
149
149
self ._pending_message_ids .append (message_id )
150
- context_id = message .contextId
150
+ context_id = message .context_id
151
151
conversation = self .get_conversation (context_id )
152
152
self ._messages .append (message )
153
153
if conversation :
@@ -165,12 +165,12 @@ async def process_message(self, message: Message):
165
165
session = await self ._session_service .get_session (
166
166
app_name = 'A2A' , user_id = 'test_user' , session_id = context_id
167
167
)
168
- task_id = message .taskId
168
+ task_id = message .task_id
169
169
# Update state must happen in an event
170
170
state_update = {
171
171
'task_id' : task_id ,
172
172
'context_id' : context_id ,
173
- 'message_id' : message .messageId ,
173
+ 'message_id' : message .message_id ,
174
174
}
175
175
# Need to upsert session state now, only way is to append an event.
176
176
await self ._session_service .append_event (
@@ -254,25 +254,25 @@ def task_callback(self, task: TaskCallbackArg, agent_card: AgentCard):
254
254
255
255
def emit_event (self , task : TaskCallbackArg , agent_card : AgentCard ):
256
256
content = None
257
- context_id = task .contextId
257
+ context_id = task .context_id
258
258
if isinstance (task , TaskStatusUpdateEvent ):
259
259
if task .status .message :
260
260
content = task .status .message
261
261
else :
262
262
content = Message (
263
263
parts = [Part (root = TextPart (text = str (task .status .state )))],
264
264
role = Role .agent ,
265
- messageId = str (uuid .uuid4 ()),
266
- contextId = context_id ,
267
- taskId = task .taskId ,
265
+ message_id = str (uuid .uuid4 ()),
266
+ context_id = context_id ,
267
+ task_id = task .task_id ,
268
268
)
269
269
elif isinstance (task , TaskArtifactUpdateEvent ):
270
270
content = Message (
271
271
parts = task .artifact .parts ,
272
272
role = Role .agent ,
273
- messageId = str (uuid .uuid4 ()),
274
- contextId = context_id ,
275
- taskId = task .taskId ,
273
+ message_id = str (uuid .uuid4 ()),
274
+ context_id = context_id ,
275
+ task_id = task .task_id ,
276
276
)
277
277
elif task .status and task .status .message :
278
278
content = task .status .message
@@ -283,17 +283,17 @@ def emit_event(self, task: TaskCallbackArg, agent_card: AgentCard):
283
283
content = Message (
284
284
parts = parts ,
285
285
role = Role .agent ,
286
- messageId = str (uuid .uuid4 ()),
287
- taskId = task .id ,
288
- contextId = context_id ,
286
+ message_id = str (uuid .uuid4 ()),
287
+ task_id = task .id ,
288
+ context_id = context_id ,
289
289
)
290
290
else :
291
291
content = Message (
292
292
parts = [Part (root = TextPart (text = str (task .status .state )))],
293
293
role = Role .agent ,
294
- messageId = str (uuid .uuid4 ()),
295
- taskId = task .id ,
296
- contextId = context_id ,
294
+ message_id = str (uuid .uuid4 ()),
295
+ task_id = task .id ,
296
+ context_id = context_id ,
297
297
)
298
298
if content :
299
299
self .add_event (
@@ -307,52 +307,52 @@ def emit_event(self, task: TaskCallbackArg, agent_card: AgentCard):
307
307
308
308
def attach_message_to_task (self , message : Message | None , task_id : str ):
309
309
if message :
310
- self ._task_map [message .messageId ] = task_id
310
+ self ._task_map [message .message_id ] = task_id
311
311
312
312
def insert_message_history (self , task : Task , message : Message | None ):
313
313
if not message :
314
314
return
315
315
if task .history is None :
316
316
task .history = []
317
- message_id = message .messageId
317
+ message_id = message .message_id
318
318
if not message_id :
319
319
return
320
320
if task .history and (
321
321
task .status .message
322
- and task .status .message .messageId
323
- not in [x .messageId for x in task .history ]
322
+ and task .status .message .message_id
323
+ not in [x .message_id for x in task .history ]
324
324
):
325
325
task .history .append (task .status .message )
326
326
elif not task .history and task .status .message :
327
327
task .history = [task .status .message ]
328
328
else :
329
329
print (
330
330
'Message id already in history' ,
331
- task .status .message .messageId if task .status .message else '' ,
331
+ task .status .message .message_id if task .status .message else '' ,
332
332
task .history ,
333
333
)
334
334
335
335
def add_or_get_task (self , event : TaskCallbackArg ):
336
336
task_id = None
337
337
if isinstance (event , Message ):
338
- task_id = event .taskId
338
+ task_id = event .task_id
339
339
elif isinstance (event , Task ):
340
340
task_id = event .id
341
341
else :
342
- task_id = event .taskId
342
+ task_id = event .task_id
343
343
if not task_id :
344
344
task_id = str (uuid .uuid4 ())
345
345
current_task = next (
346
346
filter (lambda x : x .id == task_id , self ._tasks ), None
347
347
)
348
348
if not current_task :
349
- context_id = event .contextId
349
+ context_id = event .context_id
350
350
current_task = Task (
351
351
id = task_id ,
352
352
# initialize with submitted
353
353
status = TaskStatus (state = TaskState .submitted ),
354
354
artifacts = [],
355
- contextId = context_id ,
355
+ context_id = context_id ,
356
356
)
357
357
self .add_task (current_task )
358
358
return current_task
@@ -366,32 +366,32 @@ def process_artifact_event(
366
366
if not task_update_event .append :
367
367
# received the first chunk or entire payload for an artifact
368
368
if (
369
- task_update_event .lastChunk is None
370
- or task_update_event .lastChunk
369
+ task_update_event .last_chunk is None
370
+ or task_update_event .last_chunk
371
371
):
372
- # lastChunk bit is missing or is set to true, so this is the entire payload
372
+ # last_chunk bit is missing or is set to true, so this is the entire payload
373
373
# add this to artifacts
374
374
if not current_task .artifacts :
375
375
current_task .artifacts = []
376
376
current_task .artifacts .append (artifact )
377
377
else :
378
378
# this is a chunk of an artifact, stash it in temp store for assembling
379
- if artifact .artifactId not in self ._artifact_chunks :
380
- self ._artifact_chunks [artifact .artifactId ] = []
381
- self ._artifact_chunks [artifact .artifactId ].append (artifact )
379
+ if artifact .artifact_id not in self ._artifact_chunks :
380
+ self ._artifact_chunks [artifact .artifact_id ] = []
381
+ self ._artifact_chunks [artifact .artifact_id ].append (artifact )
382
382
else :
383
383
# we received an append chunk, add to the existing temp artifact
384
- current_temp_artifact = self ._artifact_chunks [artifact .artifactId ][
384
+ current_temp_artifact = self ._artifact_chunks [artifact .artifact_id ][
385
385
- 1
386
386
]
387
387
# TODO handle if current_temp_artifact is missing
388
388
current_temp_artifact .parts .extend (artifact .parts )
389
- if task_update_event .lastChunk :
389
+ if task_update_event .last_chunk :
390
390
if current_task .artifacts :
391
391
current_task .artifacts .append (current_temp_artifact )
392
392
else :
393
393
current_task .artifacts = [current_temp_artifact ]
394
- del self ._artifact_chunks [artifact .artifactId ][- 1 ]
394
+ del self ._artifact_chunks [artifact .artifact_id ][- 1 ]
395
395
396
396
def add_event (self , event : Event ):
397
397
self ._events [event .id ] = event
@@ -475,14 +475,14 @@ def adk_content_from_message(self, message: Message) -> types.Content:
475
475
parts .append (
476
476
types .Part .from_uri (
477
477
file_uri = part .file .uri ,
478
- mime_type = part .file .mimeType ,
478
+ mime_type = part .file .mime_type ,
479
479
)
480
480
)
481
481
else :
482
482
parts .append (
483
483
types .Part .from_bytes (
484
484
data = part .file .bytes .encode ('utf-8' ),
485
- mime_type = part .file .mimeType ,
485
+ mime_type = part .file .mime_type ,
486
486
)
487
487
)
488
488
return types .Content (parts = parts , role = message .role )
@@ -498,9 +498,9 @@ async def adk_content_to_message(
498
498
return Message (
499
499
parts = [],
500
500
role = content .role if content .role == Role .user else Role .agent ,
501
- contextId = context_id ,
502
- taskId = task_id ,
503
- messageId = str (uuid .uuid4 ()),
501
+ context_id = context_id ,
502
+ task_id = task_id ,
503
+ message_id = str (uuid .uuid4 ()),
504
504
)
505
505
for part in content .parts :
506
506
if part .text :
@@ -516,7 +516,7 @@ async def adk_content_to_message(
516
516
root = FilePart (
517
517
file = FileWithBytes (
518
518
bytes = part .inline_data .decode ('utf-8' ),
519
- mimeType = part .file_data .mime_type ,
519
+ mime_type = part .file_data .mime_type ,
520
520
),
521
521
)
522
522
)
@@ -527,7 +527,7 @@ async def adk_content_to_message(
527
527
root = FilePart (
528
528
file = FileWithUri (
529
529
uri = part .file_data .file_uri ,
530
- mimeType = part .file_data .mime_type ,
530
+ mime_type = part .file_data .mime_type ,
531
531
)
532
532
)
533
533
)
@@ -559,9 +559,9 @@ async def adk_content_to_message(
559
559
return Message (
560
560
role = content .role if content .role == Role .user else Role .agent ,
561
561
parts = parts ,
562
- contextId = context_id ,
563
- taskId = task_id ,
564
- messageId = str (uuid .uuid4 ()),
562
+ context_id = context_id ,
563
+ task_id = task_id ,
564
+ message_id = str (uuid .uuid4 ()),
565
565
)
566
566
567
567
async def _handle_function_response (
@@ -594,7 +594,7 @@ async def _handle_function_response(
594
594
root = FilePart (
595
595
file = FileWithBytes (
596
596
bytes = base64_data ,
597
- mimeType = file_data .mime_type ,
597
+ mime_type = file_data .mime_type ,
598
598
name = 'artifact_file' ,
599
599
)
600
600
)
@@ -606,9 +606,9 @@ async def _handle_function_response(
606
606
content = Message (
607
607
parts = [Part (root = TextPart (text = 'Unknown content' ))],
608
608
role = Role .agent ,
609
- messageId = str (uuid .uuid4 ()),
610
- taskId = task_id ,
611
- contextId = context_id ,
609
+ message_id = str (uuid .uuid4 ()),
610
+ task_id = task_id ,
611
+ context_id = context_id ,
612
612
)
613
613
except Exception as e :
614
614
print ("Couldn't convert to messages:" , e )
0 commit comments