fix: bug when cancelling tasks, tool call message subkind
This commit is contained in:
1 parent
248146056a
commit
7e68348368
2 files changed
+7
-3
No files matched your search
@@ -148,7 +148,7 @@ class Agent:
|
|||||||
thread_id=message.thread_id,
|
thread_id=message.thread_id,
|
||||||
content=stream,
|
content=stream,
|
||||||
kind="log",
|
kind="log",
|
||||||
subkind="reasoning",
|
subkind="tool-call",
|
||||||
)
|
)
|
||||||
run.emit_event('chat-message', {
|
run.emit_event('chat-message', {
|
||||||
'messageId': new_message['id'],
|
'messageId': new_message['id'],
|
||||||
@@ -220,7 +220,10 @@ class AgentRun:
|
|||||||
self.reasoning = None
|
self.reasoning = None
|
||||||
|
|
||||||
# Cancellation tracking
|
# Cancellation tracking
|
||||||
|
# You should use 'cancelled', task and thread are for
|
||||||
|
# external tasks that cannot be cancelled reliably
|
||||||
self.task = None # For asyncio tasks
|
self.task = None # For asyncio tasks
|
||||||
|
self.thread = None
|
||||||
self.cancelled = False
|
self.cancelled = False
|
||||||
|
|
||||||
app.tmp.runs[self.id] = self
|
app.tmp.runs[self.id] = self
|
||||||
|
|||||||
@@ -358,8 +358,7 @@ async def openrouter_chat_completion(app, messages, model, tools=[], opts={}, ag
|
|||||||
|
|
||||||
async for event in stream_response:
|
async for event in stream_response:
|
||||||
if agent_run and agent_run.cancelled:
|
if agent_run and agent_run.cancelled:
|
||||||
print(f"Cancelling openrouter inference for run {agent_run.id}")
|
stream_response.cancel()
|
||||||
# TODO: Need to cancell?
|
|
||||||
break
|
break
|
||||||
|
|
||||||
if event.choices and len(event.choices) > 0:
|
if event.choices and len(event.choices) > 0:
|
||||||
@@ -402,6 +401,8 @@ async def openrouter_chat_completion(app, messages, model, tools=[], opts={}, ag
|
|||||||
def handle_done(task):
|
def handle_done(task):
|
||||||
try:
|
try:
|
||||||
task.result()
|
task.result()
|
||||||
|
except asyncio.CancelledError:
|
||||||
|
print("[openrouter] inference cancelled")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"[openrouter] Worker error: {e}")
|
print(f"[openrouter] Worker error: {e}")
|
||||||
print(traceback.format_exc())
|
print(traceback.format_exc())
|
||||||
|
|||||||
Reference in new issue
Block a user