Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Llama Index
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
Llama Index
Commits
dd593093
Unverified
Commit
dd593093
authored
2 months ago
by
Logan
Committed by
GitHub
2 months ago
Browse files
Options
Downloads
Patches
Plain Diff
safer workflow cancel + fix restored context bug (#17938)
parent
1d4c9679
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
llama-index-core/llama_index/core/agent/workflow/multi_agent_workflow.py
+2
-0
2 additions, 0 deletions
...e/llama_index/core/agent/workflow/multi_agent_workflow.py
llama-index-core/llama_index/core/workflow/workflow.py
+13
-8
13 additions, 8 deletions
llama-index-core/llama_index/core/workflow/workflow.py
with
15 additions
and
8 deletions
llama-index-core/llama_index/core/agent/workflow/multi_agent_workflow.py
+
2
−
0
View file @
dd593093
...
@@ -496,6 +496,7 @@ class AgentWorkflow(Workflow, PromptMixin, metaclass=AgentWorkflowMeta):
...
@@ -496,6 +496,7 @@ class AgentWorkflow(Workflow, PromptMixin, metaclass=AgentWorkflowMeta):
state_prompt
:
Optional
[
Union
[
str
,
BasePromptTemplate
]]
=
None
,
state_prompt
:
Optional
[
Union
[
str
,
BasePromptTemplate
]]
=
None
,
initial_state
:
Optional
[
dict
]
=
None
,
initial_state
:
Optional
[
dict
]
=
None
,
timeout
:
Optional
[
float
]
=
None
,
timeout
:
Optional
[
float
]
=
None
,
verbose
:
bool
=
False
,
)
->
"
AgentWorkflow
"
:
)
->
"
AgentWorkflow
"
:
"""
Initializes an AgentWorkflow from a list of tools or functions.
"""
Initializes an AgentWorkflow from a list of tools or functions.
...
@@ -528,4 +529,5 @@ class AgentWorkflow(Workflow, PromptMixin, metaclass=AgentWorkflowMeta):
...
@@ -528,4 +529,5 @@ class AgentWorkflow(Workflow, PromptMixin, metaclass=AgentWorkflowMeta):
state_prompt
=
state_prompt
,
state_prompt
=
state_prompt
,
initial_state
=
initial_state
,
initial_state
=
initial_state
,
timeout
=
timeout
,
timeout
=
timeout
,
verbose
=
verbose
,
)
)
This diff is collapsed.
Click to expand it.
llama-index-core/llama_index/core/workflow/workflow.py
+
13
−
8
View file @
dd593093
...
@@ -369,8 +369,11 @@ class Workflow(metaclass=WorkflowMeta):
...
@@ -369,8 +369,11 @@ class Workflow(metaclass=WorkflowMeta):
# add dedicated cancel task
# add dedicated cancel task
async
def
_cancel_workflow_task
()
->
None
:
async
def
_cancel_workflow_task
()
->
None
:
await
ctx
.
_cancel_flag
.
wait
()
try
:
raise
WorkflowCancelledByUser
await
ctx
.
_cancel_flag
.
wait
()
raise
WorkflowCancelledByUser
except
asyncio
.
CancelledError
:
return
ctx
.
_tasks
.
add
(
ctx
.
_tasks
.
add
(
asyncio
.
create_task
(
asyncio
.
create_task
(
...
@@ -458,11 +461,6 @@ class Workflow(metaclass=WorkflowMeta):
...
@@ -458,11 +461,6 @@ class Workflow(metaclass=WorkflowMeta):
# the context is now running
# the context is now running
ctx
.
is_running
=
True
ctx
.
is_running
=
True
else
:
# resend in-progress events if already running
for
name
,
evs
in
ctx
.
_in_progress
.
items
():
for
ev
in
evs
:
ctx
.
send_event
(
ev
,
step
=
name
)
done
,
unfinished
=
await
asyncio
.
wait
(
done
,
unfinished
=
await
asyncio
.
wait
(
ctx
.
_tasks
,
ctx
.
_tasks
,
...
@@ -485,7 +483,14 @@ class Workflow(metaclass=WorkflowMeta):
...
@@ -485,7 +483,14 @@ class Workflow(metaclass=WorkflowMeta):
t
.
cancel
()
t
.
cancel
()
# wait for cancelled tasks to cleanup
# wait for cancelled tasks to cleanup
await
asyncio
.
gather
(
*
unfinished
,
return_exceptions
=
True
)
# prevents any tasks from being stuck
try
:
await
asyncio
.
wait_for
(
asyncio
.
gather
(
*
unfinished
,
return_exceptions
=
True
),
timeout
=
0.5
,
)
except
asyncio
.
TimeoutError
:
logger
.
warning
(
"
Some tasks did not clean up within timeout
"
)
# the context is no longer running
# the context is no longer running
ctx
.
is_running
=
False
ctx
.
is_running
=
False
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment