Skip to content

Commit bdce669

Browse files
committed
Revert sync template
1 parent b71fc8e commit bdce669

File tree

1 file changed

+15
-64
lines changed
  • src/agentex/lib/cli/templates/sync/project

1 file changed

+15
-64
lines changed
Lines changed: 15 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,26 @@
1-
import json
2-
from agentex.lib import adk
1+
from typing import AsyncGenerator, Union
32
from agentex.lib.sdk.fastacp.fastacp import FastACP
4-
from agentex.lib.types.fastacp import AgenticACPConfig
5-
from agentex.lib.types.acp import CancelTaskParams, CreateTaskParams, SendEventParams
3+
from agentex.lib.types.acp import SendMessageParams
64

5+
from agentex.lib.types.task_message_updates import TaskMessageUpdate
6+
from agentex.types.task_message_content import TaskMessageContent
77
from agentex.types.text_content import TextContent
88
from agentex.lib.utils.logging import make_logger
99

1010
logger = make_logger(__name__)
1111

1212

13-
# Create an ACP server with base configuration
14-
# This sets up the core server that will handle task creation, events, and cancellation
13+
# Create an ACP server
1514
acp = FastACP.create(
16-
acp_type="agentic",
17-
config=AgenticACPConfig(
18-
type="base",
19-
),
15+
acp_type="sync",
2016
)
2117

22-
@acp.on_task_create
23-
async def handle_task_create(params: CreateTaskParams):
24-
# This handler is called first whenever a new task is created.
25-
# It's a good place to initialize any state or resources needed for the task.
26-
27-
#########################################################
28-
# 1. (👋) Do task initialization here.
29-
#########################################################
30-
31-
# Acknowledge that the task has been created.
32-
await adk.messages.create(
33-
task_id=params.task.id,
34-
content=TextContent(
35-
author="agent",
36-
content=f"Hello! I've received your task. Normally you can do some state initialization here, or just pass and do nothing until you get your first event. For now I'm just acknowledging that I've received a task with the following params:\n\n{json.dumps(params.params, indent=2)}.\n\nYou should only see this message once, when the task is created. All subsequent events will be handled by the `on_task_event_send` handler.",
37-
),
38-
)
39-
40-
@acp.on_task_event_send
41-
async def handle_event_send(params: SendEventParams):
42-
# This handler is called whenever a new event (like a message) is sent to the task
43-
44-
#########################################################
45-
# 2. (👋) Echo back the client's message to show it in the UI.
46-
#########################################################
47-
48-
# This is not done by default so the agent developer has full control over what is shown to the user.
49-
if params.event.content:
50-
await adk.messages.create(task_id=params.task.id, content=params.event.content)
51-
52-
#########################################################
53-
# 3. (👋) Send a simple response message.
54-
#########################################################
55-
56-
# In future tutorials, this is where we'll add more sophisticated response logic.
57-
await adk.messages.create(
58-
task_id=params.task.id,
59-
content=TextContent(
60-
author="agent",
61-
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.",
62-
),
63-
)
64-
65-
@acp.on_task_cancel
66-
async def handle_task_cancel(params: CancelTaskParams):
67-
# This handler is called when a task is cancelled.
68-
# It's useful for cleaning up any resources or state associated with the task.
69-
70-
#########################################################
71-
# 4. (👋) Do task cleanup here.
72-
#########################################################
73-
74-
# This is mostly for durable workflows that are cancellable like Temporal, but we will leave it here for demonstration purposes.
75-
logger.info(f"Hello! I've received task cancel for task {params.task.id}: {params.task}. This isn't necessary for this example, but it's good to know that it's available.")
18+
@acp.on_message_send
19+
async def handle_message_send(
20+
params: SendMessageParams
21+
) -> TaskMessageContent | list[TaskMessageContent] | AsyncGenerator[TaskMessageUpdate, None]:
22+
"""Default message handler with streaming support"""
23+
return TextContent(
24+
author="agent",
25+
content=f"Hello! I've received your message. Here's a generic response, but in future tutorials we'll see how you can get me to intelligently respond to your message. This is what I heard you say: {params.content.content}",
26+
)

0 commit comments

Comments
 (0)