You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Description | A production-grade agent framework developed by Tencent, supporting multiple model providers (including OpenAI, Anthropic, DeepSeek, and LiteLLM). It provides tool-calling capabilities, multi-agent orchestration, session and long-term memory management, RAG-based knowledge, and seamless deployment as a service via FastAPI. |
Copy file name to clipboardExpand all lines: docs/mkdocs/en/cancel.md
+46-7Lines changed: 46 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
During Agent execution, the output may sometimes not meet the user's requirements. In such cases, users often interrupt the Agent execution, provide partial feedback (indicating which outputs before the interruption were unsatisfactory and what should be done next), and then let the Agent continue execution.
4
4
5
-
For this scenario, the trpc-agent framework provides a Cancel mechanism that allows cancelling an Agent's ongoing operations while preserving partial content (content being streamed by the LLM, tool execution results in progress, etc.). This mechanism is based on a checkpoint design. During execution, each Agent checks at checkpoint locations (after an LLM streaming output chunk, after a tool call completes, etc.) whether the current Agent should be terminated. If termination is required, an exception is thrown, and the framework records and saves the partial information to the session history.
5
+
For this scenario, the trpc-agent-python framework provides a Cancel mechanism that allows cancelling an Agent's ongoing operations while preserving partial content (content being streamed by the LLM, tool execution results in progress, etc.). This mechanism is based on a checkpoint design. During execution, each Agent checks at checkpoint locations (after an LLM streaming output chunk, after a tool call completes, etc.) whether the current Agent should be terminated. If termination is required, an exception is thrown, and the framework records and saves the partial information to the session history.
6
6
7
7
This capability has been integrated into all Agents provided by the framework. Custom Agents implemented by other services can also be easily integrated.
8
8
@@ -73,9 +73,11 @@ When an Agent is cancelled, different session management strategies are applied
73
73
```python
74
74
import asyncio
75
75
import uuid
76
+
76
77
from trpc_agent_sdk.runners import Runner
77
78
from trpc_agent_sdk.sessions import InMemorySessionService
78
79
from trpc_agent_sdk.types import Content, Part
80
+
from trpc_agent_sdk.events import AgentCancelledEvent
79
81
80
82
asyncdefmain():
81
83
runner = Runner(
@@ -111,7 +113,11 @@ async def main():
111
113
await asyncio.sleep(2)
112
114
113
115
# Cancel the run using the same user_id and session_id
114
-
runner2 = Runner(xxxx)
116
+
runner2 = Runner(
117
+
app_name="my_app",
118
+
agent=my_agent,
119
+
session_service=InMemorySessionService(),
120
+
)
115
121
success =await runner2.cancel_run_async(
116
122
user_id=user_id,
117
123
session_id=session_id,
@@ -136,6 +142,7 @@ The following is an example based on FastAPI SSE:
136
142
137
143
```python
138
144
import asyncio
145
+
139
146
from fastapi import FastAPI, Request
140
147
from fastapi.responses import StreamingResponse
141
148
from trpc_agent_sdk.runners import Runner
@@ -216,8 +223,20 @@ If a standalone cancel interface (e.g., REST API) is needed, note the following
216
223
```python
217
224
from fastapi import FastAPI, HTTPException
218
225
226
+
from trpc_agent_sdk.runners import Runner
227
+
from trpc_agent_sdk.agents import LlmAgent
228
+
from trpc_agent_sdk.sessions import InMemorySessionService
229
+
219
230
app = FastAPI()
220
-
runner = Runner(...)
231
+
232
+
agent = LlmAgent(name="my_agent", model=model, instruction="You are an intelligent assistant")
0 commit comments