Skip to content

Commit 5c787a6

Browse files
authored
Merge pull request #3 from mdrideout/j-117-factory-functions-allow-function-params
Docs update
2 parents ab10591 + f892584 commit 5c787a6

File tree

3 files changed

+67
-2
lines changed

3 files changed

+67
-2
lines changed

docs/core_concepts.rst

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,4 +159,34 @@ A `Workflow` is the main executable component that takes a `graph_factory` and a
159159
)
160160
)
161161
162-
await sample_workflow.execute()
162+
await sample_workflow.execute()
163+
164+
**Passing Parameters to Factories**
165+
166+
To provide parameters to your `graph_factory` or `store_factory` when
167+
you create a `Workflow`, you can wrap your factory function call in a
168+
`lambda`. This creates a new, argument-less factory that calls your
169+
function with the desired parameters when executed.
170+
171+
This is useful for injecting dependencies like configuration objects or
172+
API clients into your graph at instantiation time, while preserving
173+
concurrency safety.
174+
175+
.. code-block:: python
176+
177+
# Your factory function that requires a dependency
178+
def create_graph_with_dependency(api_key: str) -> Graph:
179+
# ... setup graph using the api_key
180+
return Graph(...)
181+
182+
# Instantiate the workflow, using a lambda to create the factory
183+
workflow = Workflow[MyState, MyStore](
184+
name="configured_workflow",
185+
graph_factory=lambda: create_graph_with_dependency(
186+
api_key="your-secret-key"
187+
),
188+
store_factory=lambda: MyStore(initial_state=MyState())
189+
)
190+
191+
# The workflow can now be executed normally
192+
await workflow.execute()

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "junjo"
7-
version = "0.50.0"
7+
version = "0.50.1"
88
description = "A graph workflow execution library for building agentic AI workflows."
99
readme = "README.md"
1010
requires-python = ">=3.11"

src/junjo/workflow.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,41 @@ def __init__(
300300
hook_manager=HookManager(verbose_logging=False, open_telemetry=True),
301301
)
302302
await workflow.execute()
303+
304+
.. _workflow-instantiation-params:
305+
306+
**Passing Parameters to Factories**
307+
308+
To provide parameters to your `graph_factory` or `store_factory` when
309+
you create a `Workflow`, you can wrap your factory function call in a
310+
`lambda`. This creates a new, argument-less factory that calls your
311+
function with the desired parameters when executed.
312+
313+
This is useful for injecting dependencies like configuration objects or
314+
API clients into your graph at instantiation time, while preserving
315+
concurrency safety.
316+
317+
.. code-block:: python
318+
319+
# Your factory function that requires a dependency
320+
def create_graph_with_dependency(emulator: Emulator) -> Graph:
321+
# ... setup graph using the emulator
322+
return Graph(...)
323+
324+
# An instance of the dependency
325+
my_emulator = Emulator()
326+
327+
# Instantiate the workflow, using a lambda to create the factory
328+
workflow = Workflow[MyState, MyStore](
329+
name="configured_workflow",
330+
graph_factory=lambda: create_graph_with_dependency(
331+
emulator=my_emulator
332+
),
333+
store_factory=lambda: MyStore(initial_state=MyState())
334+
)
335+
336+
# The workflow can now be executed normally
337+
await workflow.execute()
303338
"""
304339
super().__init__(
305340
graph_factory=graph_factory,

0 commit comments

Comments
 (0)