Skip to content

Commit 98c566f

Browse files
committed
Fix async tutorail
1 parent 1c259a8 commit 98c566f

File tree

1 file changed

+16
-19
lines changed
  • src/agentex/lib/cli/templates/default/project

1 file changed

+16
-19
lines changed

src/agentex/lib/cli/templates/default/project/acp.py.j2

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,36 +12,33 @@ acp = FastACP.create(
1212

1313
@acp.on_task_event_send
1414
async def handle_task_event_send(params: SendEventParams):
15-
# For this tutorial, we print the parameters sent to the handler
16-
# so you can see where and how messages within a task are handled
17-
print(f"Hello world! I just received this message: {params}")
18-
15+
# For this tutorial, we log the parameters sent to the handler
16+
# so you can see where and how messages within a long running task are handled
17+
logger.info(f"Received task event send rpc: {params}")
18+
19+
# 1. Echo back the client's message to show it in the UI. This is not done by default so the agent developer has full control over what is shown to the user.
20+
await adk.messages.create(task_id=params.task.id, content=params.event.content)
21+
22+
# 2. Send a simple response message.
23+
# In future tutorials, this is where we'll add more sophisticated response logic.
1924
await adk.messages.create(
2025
task_id=params.task.id,
21-
trace_id=params.task.id,
22-
content=TextContent(
23-
author="user",
24-
content=params.event.content,
25-
),
26-
)
27-
28-
await adk.messages.create(
29-
task_id=params.task.id,
30-
trace_id=params.task.id,
3126
content=TextContent(
3227
author="agent",
33-
content="Hello world! I just received this message: {params.event.content}",
28+
content=f"Hello! I've received your message. I can't respond right now, but in future tutorials we'll see how you can get me to intelligently respond to your message.",
3429
),
35-
)
30+
)
3631

3732
@acp.on_task_cancel
3833
async def handle_task_canceled(params: CancelTaskParams):
3934
# For this tutorial, we print the parameters sent to the handler
4035
# so you can see where and how task cancellation is handled
41-
print(f"Hello world! Task canceled: {params.task.id}")
36+
logger.info(f"Received task cancel rpc: {params}")
4237

4338
@acp.on_task_create
4439
async def handle_task_create(params: CreateTaskParams):
45-
# For this tutorial, we print the parameters sent to the handler
40+
# For this tutorial, we log the parameters sent to the handler
4641
# so you can see where and how task creation is handled
47-
print(f"Hello world! Task created: {params.task.id}")
42+
43+
# Here is where you can initialize any state or resources needed for the task.
44+
logger.info(f"Received task create rpc: {params}")

0 commit comments

Comments
 (0)