Skip to content

Commit 3ba8abf

Browse files
author
Chojan Shang
committed
refactor: try to make examples work
Signed-off-by: Chojan Shang <chojan.shang@vesoft.com>
1 parent d03aa97 commit 3ba8abf

File tree

6 files changed

+66
-73
lines changed

6 files changed

+66
-73
lines changed

docs/index.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from acp import (
2525
SessionNotification,
2626
stdio_streams,
2727
)
28-
from acp.schema import ContentBlock1, SessionUpdate2
28+
from acp.schema import TextContentBlock, AgentMessageChunk
2929

3030

3131
class EchoAgent(Agent):
@@ -44,9 +44,9 @@ class EchoAgent(Agent):
4444
await self._conn.sessionUpdate(
4545
SessionNotification(
4646
sessionId=params.sessionId,
47-
update=SessionUpdate2(
47+
update=AgentMessageChunk(
4848
sessionUpdate="agent_message_chunk",
49-
content=ContentBlock1(type="text", text=text),
49+
content=TextContentBlock(type="text", text=text),
5050
),
5151
)
5252
)

docs/quickstart.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ from acp import (
2525
SessionNotification,
2626
stdio_streams,
2727
)
28-
from acp.schema import ContentBlock1, SessionUpdate2
28+
from acp.schema import TextContentBlock, AgentMessageChunk
2929

3030

3131
class EchoAgent(Agent):
@@ -44,9 +44,9 @@ class EchoAgent(Agent):
4444
await self._conn.sessionUpdate(
4545
SessionNotification(
4646
sessionId=params.sessionId,
47-
update=SessionUpdate2(
47+
update=AgentMessageChunk(
4848
sessionUpdate="agent_message_chunk",
49-
content=ContentBlock1(type="text", text=text),
49+
content=TextContentBlock(type="text", text=text),
5050
),
5151
)
5252
)

examples/agent.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
stdio_streams,
2020
PROTOCOL_VERSION,
2121
)
22-
from acp.schema import ContentBlock1, SessionUpdate2
22+
from acp.schema import TextContentBlock, AgentMessageChunk
2323

2424

2525
class ExampleAgent(Agent):
@@ -50,9 +50,9 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
5050
await self._conn.sessionUpdate(
5151
SessionNotification(
5252
sessionId=params.sessionId,
53-
update=SessionUpdate2(
53+
update=AgentMessageChunk(
5454
sessionUpdate="agent_message_chunk",
55-
content=ContentBlock1(type="text", text="Client sent: "),
55+
content=TextContentBlock(type="text", text="Client sent: "),
5656
),
5757
)
5858
)
@@ -65,14 +65,14 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
6565
else:
6666
text = f"<{block.get('type', 'content')}>"
6767
else:
68-
# pydantic model ContentBlock1
68+
# pydantic model TextContentBlock
6969
text = getattr(block, "text", "<content>")
7070
await self._conn.sessionUpdate(
7171
SessionNotification(
7272
sessionId=params.sessionId,
73-
update=SessionUpdate2(
73+
update=AgentMessageChunk(
7474
sessionUpdate="agent_message_chunk",
75-
content=ContentBlock1(type="text", text=text),
75+
content=TextContentBlock(type="text", text=text),
7676
),
7777
)
7878
)

examples/echo_agent.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
SessionNotification,
1313
stdio_streams,
1414
)
15-
from acp.schema import ContentBlock1, SessionUpdate2
15+
from acp.schema import TextContentBlock, AgentMessageChunk
1616

1717

1818
class EchoAgent(Agent):
@@ -31,9 +31,9 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
3131
await self._conn.sessionUpdate(
3232
SessionNotification(
3333
sessionId=params.sessionId,
34-
update=SessionUpdate2(
34+
update=AgentMessageChunk(
3535
sessionUpdate="agent_message_chunk",
36-
content=ContentBlock1(type="text", text=text),
36+
content=TextContentBlock(type="text", text=text),
3737
),
3838
)
3939
)

examples/mini_swe_agent/agent.py

Lines changed: 30 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,17 @@
2626
PROTOCOL_VERSION,
2727
)
2828
from acp.schema import (
29-
ContentBlock1,
29+
AgentMessageChunk,
30+
AgentThoughtChunk,
31+
AllowedOutcome,
32+
ContentToolCallContent,
3033
PermissionOption,
3134
RequestPermissionRequest,
3235
RequestPermissionResponse,
33-
RequestPermissionOutcome1,
34-
RequestPermissionOutcome2,
35-
SessionUpdate1,
36-
SessionUpdate2,
37-
SessionUpdate3,
38-
SessionUpdate4,
39-
SessionUpdate5,
40-
ToolCallContent1,
36+
TextContentBlock,
37+
ToolCallStart,
4138
ToolCallUpdate,
39+
UserMessageChunk,
4240
)
4341

4442

@@ -130,9 +128,9 @@ def _send_cost_hint(self) -> None:
130128
cost = float(getattr(self.model, "cost", 0.0))
131129
except Exception:
132130
cost = 0.0
133-
hint = SessionUpdate3(
131+
hint = AgentThoughtChunk(
134132
sessionUpdate="agent_thought_chunk",
135-
content=ContentBlock1(type="text", text=f"__COST__:{cost:.2f}"),
133+
content=TextContentBlock(type="text", text=f"__COST__:{cost:.2f}"),
136134
)
137135
try:
138136
loop = asyncio.get_running_loop()
@@ -142,15 +140,15 @@ def _send_cost_hint(self) -> None:
142140

143141
async def on_tool_start(self, title: str, command: str, tool_call_id: str) -> None:
144142
"""Send a tool_call start notification for a bash command."""
145-
update = SessionUpdate4(
143+
update = ToolCallStart(
146144
sessionUpdate="tool_call",
147145
toolCallId=tool_call_id,
148146
title=title,
149147
kind="execute",
150148
status="pending",
151149
content=[
152-
ToolCallContent1(
153-
type="content", content=ContentBlock1(type="text", text=f"```bash\n{command}\n```")
150+
ContentToolCallContent(
151+
type="content", content=TextContentBlock(type="text", text=f"```bash\n{command}\n```")
154152
)
155153
],
156154
rawInput={"command": command},
@@ -166,13 +164,13 @@ async def on_tool_complete(
166164
status: str = "completed",
167165
) -> None:
168166
"""Send a tool_call_update with the final output and return code."""
169-
update = SessionUpdate5(
167+
update = ToolCallUpdate(
170168
sessionUpdate="tool_call_update",
171169
toolCallId=tool_call_id,
172170
status=status,
173171
content=[
174-
ToolCallContent1(
175-
type="content", content=ContentBlock1(type="text", text=f"```ansi\n{output}\n```")
172+
ContentToolCallContent(
173+
type="content", content=TextContentBlock(type="text", text=f"```ansi\n{output}\n```")
176174
)
177175
],
178176
rawOutput={"output": output, "returncode": returncode},
@@ -185,8 +183,8 @@ def add_message(self, role: str, content: str, **kwargs):
185183
if not getattr(self, "_emit_updates", True) or role != "assistant":
186184
return
187185
text = str(content)
188-
block = ContentBlock1(type="text", text=text)
189-
update = SessionUpdate2(sessionUpdate="agent_message_chunk", content=block)
186+
block = TextContentBlock(type="text", text=text)
187+
update = AgentMessageChunk(sessionUpdate="agent_message_chunk", content=block)
190188
try:
191189
loop = asyncio.get_running_loop()
192190
loop.create_task(self._send(update))
@@ -203,14 +201,15 @@ def _confirm_action_sync(self, tool_call_id: str, command: str) -> bool:
203201
PermissionOption(optionId="reject-once", name="Reject", kind="reject_once"),
204202
],
205203
toolCall=ToolCallUpdate(
204+
sessionUpdate="tool_call_update",
206205
toolCallId=tool_call_id,
207206
title="bash",
208207
kind="execute",
209208
status="pending",
210209
content=[
211-
ToolCallContent1(
210+
ContentToolCallContent(
212211
type="content",
213-
content=ContentBlock1(type="text", text=f"```bash\n{command}\n```"),
212+
content=TextContentBlock(type="text", text=f"```bash\n{command}\n```"),
214213
)
215214
],
216215
rawInput={"command": command},
@@ -222,7 +221,7 @@ def _confirm_action_sync(self, tool_call_id: str, command: str) -> bool:
222221
except Exception:
223222
return False
224223
out = resp.outcome
225-
if isinstance(out, RequestPermissionOutcome2) and out.optionId in ("allow-once", "allow-always"):
224+
if isinstance(out, AllowedOutcome) and out.optionId in ("allow-once", "allow-always"):
226225
return True
227226
return False
228227

@@ -253,7 +252,7 @@ def execute_action(self, action: dict) -> dict: # type: ignore[override]
253252
# Mark in progress
254253
self._schedule(
255254
self._send(
256-
SessionUpdate5(
255+
ToolCallUpdate(
257256
sessionUpdate="tool_call_update",
258257
toolCallId=tool_id,
259258
status="in_progress",
@@ -428,9 +427,9 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
428427
await self._client.sessionUpdate(
429428
SessionNotification(
430429
sessionId=params.sessionId,
431-
update=SessionUpdate2(
430+
update=AgentMessageChunk(
432431
sessionUpdate="agent_message_chunk",
433-
content=ContentBlock1(
432+
content=TextContentBlock(
434433
type="text",
435434
text=(
436435
"mini-swe-agent load error: "
@@ -476,9 +475,9 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
476475
await self._client.sessionUpdate(
477476
SessionNotification(
478477
sessionId=params.sessionId,
479-
update=SessionUpdate2(
478+
update=AgentMessageChunk(
480479
sessionUpdate="agent_message_chunk",
481-
content=ContentBlock1(type="text", text="Human mode: please submit a bash command."),
480+
content=TextContentBlock(type="text", text="Human mode: please submit a bash command."),
482481
),
483482
)
484483
)
@@ -508,9 +507,9 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
508507
await self._client.sessionUpdate(
509508
SessionNotification(
510509
sessionId=params.sessionId,
511-
update=SessionUpdate2(
510+
update=AgentMessageChunk(
512511
sessionUpdate="agent_message_chunk",
513-
content=ContentBlock1(
512+
content=TextContentBlock(
514513
type="text",
515514
text=(
516515
"Agent finished. Type a new task in the next message to continue, or do nothing to end."
@@ -528,9 +527,9 @@ async def prompt(self, params: PromptRequest) -> PromptResponse:
528527
await self._client.sessionUpdate(
529528
SessionNotification(
530529
sessionId=params.sessionId,
531-
update=SessionUpdate2(
530+
update=AgentMessageChunk(
532531
sessionUpdate="agent_message_chunk",
533-
content=ContentBlock1(type="text", text=f"Error while processing: {e}"),
532+
content=TextContentBlock(type="text", text=f"Error while processing: {e}"),
534533
),
535534
)
536535
)

0 commit comments

Comments
 (0)