Skip to content

Commit 18d9bb9

Browse files
authored
Refactor context to (eventually) support runtime plugins (#127)
1 parent cf25ca6 commit 18d9bb9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+7945
-1404
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ jobs:
1818
- name: Run linter
1919
shell: bash
2020
run: |
21-
uv sync --all-extras
21+
uv sync --all-extras --all-packages
2222
uv run -- pre-commit run -a

.github/workflows/publish_release.yml

Lines changed: 56 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ on:
1919
type: string
2020
push:
2121
tags:
22-
- "v*"
22+
- "v*" # core package tags
23+
- "*@v*" # package-scoped tags like [email protected]
2324

2425
jobs:
2526
build-n-publish:
@@ -28,6 +29,15 @@ jobs:
2829
runs-on: ubuntu-latest
2930
permissions:
3031
contents: write
32+
strategy:
33+
fail-fast: false
34+
matrix:
35+
package: [llama-index-workflows, llama-index-utils-workflow]
36+
include:
37+
- package: llama-index-workflows
38+
is_core: true
39+
- package: llama-index-utils-workflow
40+
is_core: false
3141

3242
steps:
3343
- uses: actions/checkout@v4
@@ -37,42 +47,76 @@ jobs:
3747
- name: Install uv
3848
uses: astral-sh/setup-uv@v6
3949

40-
- name: Validate version
41-
if: startsWith(github.ref, 'refs/tags/')
50+
- name: Parse tag
51+
id: tag
52+
run: |
53+
REF_NAME="${GITHUB_REF_NAME}"
54+
if [[ "${REF_NAME}" == v* ]]; then
55+
PKG="llama-index-workflows"
56+
VERSION="${REF_NAME#v}"
57+
else
58+
# strip optional leading '@'
59+
REF_TRIMMED="${REF_NAME#@}"
60+
PKG_PART="${REF_TRIMMED%@v*}"
61+
PKG="${PKG_PART}"
62+
VERSION_PART="${REF_TRIMMED#*@v}"
63+
VERSION="${VERSION_PART}"
64+
fi
65+
echo "package=${PKG}" >> $GITHUB_OUTPUT
66+
echo "version=${VERSION}" >> $GITHUB_OUTPUT
67+
68+
- name: Compute directory flag
69+
id: dir
70+
run: |
71+
if [ "${{ matrix.is_core }}" = "true" ]; then
72+
echo "dir_flag=" >> $GITHUB_OUTPUT
73+
else
74+
echo "dir_flag=--directory packages/${{ matrix.package }}" >> $GITHUB_OUTPUT
75+
fi
76+
77+
- name: Guard non-target matrix entry
78+
if: steps.tag.outputs.package != matrix.package
79+
run: echo "Skipping matrix package ${{ matrix.package }} for tag ${{ steps.tag.outputs.package }}" && exit 0
80+
81+
- name: Validate version (core only)
82+
if: startsWith(github.ref, 'refs/tags/') && matrix.is_core == true
4283
run: uv run python scripts/validate_version.py
4384

4485
- name: Set version output
4586
id: version
4687
run: |
47-
VERSION=$(uv run python -c "from importlib.metadata import version; print(version('llama-index-workflows'))")
88+
VERSION=$(uv run ${{ steps.dir.outputs.dir_flag }} python -c "from importlib.metadata import version; print(version('${{ matrix.package }}'))")
4889
echo "Version: $VERSION"
4990
echo "version=$VERSION" >> $GITHUB_OUTPUT
5091
5192
- name: Build and publish
5293
env:
5394
UV_PUBLISH_TOKEN: ${{ secrets.PYPI_TOKEN }}
5495
run: |
55-
uv build
56-
uv publish
96+
uv build ${{ steps.dir.outputs.dir_flag }}
97+
uv publish ${{ steps.dir.outputs.dir_flag }}
5798
58-
- name: Generate OpenAPI spec
99+
- name: Generate OpenAPI spec (core only)
100+
if: matrix.is_core == true
59101
run: |
60102
uv sync --all-extras
61103
uv run hatch run server:openapi
62104
63-
- name: Create GitHub Release
105+
- name: Create GitHub Release (core only)
106+
if: matrix.is_core == true
64107
uses: ncipollo/release-action@v1
65108
with:
66109
artifacts: "dist/*,openapi.json"
67110
generateReleaseNotes: true
68111

69-
- name: Detect change type for tags
112+
- name: Detect change type for tags (core only)
70113
id: detect_change
71-
if: startsWith(github.ref, 'refs/tags/')
114+
if: startsWith(github.ref, 'refs/tags/') && matrix.is_core == true
72115
run: uv run python scripts/detect_change_type.py
73116

74117
- name: Set SDK trigger parameters
75118
id: sdk_params
119+
if: matrix.is_core == true
76120
run: |
77121
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
78122
echo "change_type=${{ github.event.inputs.server_change_type }}" >> $GITHUB_OUTPUT
@@ -84,14 +128,15 @@ jobs:
84128
85129
- name: Generate GitHub App Token
86130
id: app-token
131+
if: matrix.is_core == true
87132
uses: actions/create-github-app-token@v1
88133
with:
89134
app-id: ${{ secrets.CI_BOT_APP_ID }}
90135
private-key: ${{ secrets.CI_BOT_PRIVATE_KEY }}
91136
owner: run-llama
92137

93138
- name: Trigger SDK Update
94-
if: steps.sdk_params.outputs.change_type != 'none' && steps.sdk_params.outputs.change_type != ''
139+
if: matrix.is_core == true && steps.sdk_params.outputs.change_type != 'none' && steps.sdk_params.outputs.change_type != ''
95140
uses: peter-evans/repository-dispatch@v3
96141
with:
97142
token: ${{ steps.app-token.outputs.token }}

.github/workflows/test.yml

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@ jobs:
1717
fail-fast: false
1818
matrix:
1919
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
20+
package: [llama-index-workflows, llama-index-utils-workflow]
21+
include:
22+
- package: llama-index-workflows
23+
is_root: true
24+
coverage_report: true
25+
- package: llama-index-utils-workflow
26+
is_root: false
27+
coverage_report: false
2028
steps:
2129
- uses: actions/checkout@v4
2230
with:
@@ -28,16 +36,22 @@ jobs:
2836
python-version: ${{ matrix.python-version }}
2937
enable-cache: true
3038

31-
- name: Run tests
32-
if: matrix.python-version != env.COV_PYTHON_VERSION
33-
run: uv run --all-extras pytest
39+
- name: Compute directory flag
40+
run: |
41+
if [ "${{ matrix.is_root }}" = "true" ]; then
42+
echo "DIR_FLAG=" >> $GITHUB_ENV
43+
else
44+
echo "DIR_FLAG=--directory packages/${{ matrix.package }}" >> $GITHUB_ENV
45+
fi
46+
47+
- name: Sync dev dependencies for selected package
48+
run: uv sync --all-extras $DIR_FLAG --group dev
3449

3550
- name: Run tests with coverage
36-
if: matrix.python-version == env.COV_PYTHON_VERSION
37-
run: uv run --all-extras -- pytest --cov --cov-report=xml
51+
run: uv run --all-extras $DIR_FLAG -- pytest --cov --cov-report=xml
3852

3953
- name: Report Coveralls
40-
if: matrix.python-version == env.COV_PYTHON_VERSION
54+
if: matrix.coverage_report == true && matrix.python-version == env.COV_PYTHON_VERSION
4155
uses: coverallsapp/github-action@v2
4256
env:
4357
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}

docs/api_docs/docs/api_reference/context.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
show_root_heading: true
44
show_root_full_path: false
55
members:
6-
- __init__
76
- collect_events
87
- from_dict
98
- get_result

docs/src/content/docs/llamaagents/workflows/drawing.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ draw_all_possible_flows(JokeFlow, filename="joke_flow_all.html")
2323

2424
# Draw an execution
2525
w = JokeFlow()
26-
await w.run(topic="Pirates")
27-
draw_most_recent_execution(w, filename="joke_flow_recent.html")
26+
handler = w.run(topic="Pirates")
27+
await handler
28+
draw_most_recent_execution(handler, filename="joke_flow_recent.html")
2829
```
2930

3031
<div id="working-with-global-context-state"></div>

docs/src/content/docs/llamaagents/workflows/managing_events.md

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -117,12 +117,11 @@ async for event in handler.stream_events():
117117
result = await handler
118118
```
119119

120-
There is also the possibility of streaming internal events (such as changes occurring while the step is running, modifications of the workflow state or variations in the size of the internal queues). In order to do so, you need to pass `expose_internal = True` to `stream_events`.
120+
There is also the possibility of streaming internal events (such as changes occurring while the step is running and modifications of the workflow state). In order to do so, you need to pass `expose_internal = True` to `stream_events`.
121121

122-
All the internal events are instances of `InternalDispatchEvent`, but they can be divided into two sub-classes:
122+
All the internal events are instances of `InternalDispatchEvent`. The primary internal event is:
123123

124-
- `StepStateChanged`: exposes internal changes in the state of the event, including whether the step is running or in progress, what worker it is running on and what events it takes as input and output, as well as changes in the workflow state.
125-
- `EventsQueueChanged`: reports the state of the internal queues.
124+
- `StepStateChanged`: exposes internal changes in the state of the event, including whether the step is PREPARING (queued), RUNNING, or NOT_RUNNING, what worker it is running on and what events it takes as input and output.
126125

127126
Here is how you can stream these internal events:
128127

@@ -138,9 +137,6 @@ async for event in handler.stream_events(expose_internal=True):
138137
print("Input event for current step:", event.input_event_name)
139138
print("Workflow state at current step:", event.context_state or "No state reported")
140139
print("Output event of current step:", event.output_event_name or "No output event yet")
141-
elif isinstance(event, EventsQueueChanged):
142-
print("Queue name:", event.name)
143-
print("Queue size:", event.size)
144140
# other event streaming logic here
145141

146142
result = await handler

0 commit comments

Comments
 (0)