Skip to content

run_nodes

Class info

🛈 DocStrings

Automatic agent function execution.

run_nodes

run_nodes(config: JoinablePathLike | AgentsManifest, **kwargs: Any) -> dict[str, Any]

Run node functions synchronously.

Convenience wrapper around run_nodes_async for sync contexts. See run_nodes_async for full documentation.

Parameters:

Name Type Description Default
config JoinablePathLike | AgentsManifest

Agent configuration path

required
**kwargs Any

Arguments to pass to run_nodes_async

{}

Returns:

Type Description
dict[str, Any]

Dict mapping function names to their results

Source code in src/llmling_agent/running/run_nodes.py
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def run_nodes(config: JoinablePathLike | AgentsManifest, **kwargs: Any) -> dict[str, Any]:
    """Run node functions synchronously.

    Convenience wrapper around run_nodes_async for sync contexts.
    See run_nodes_async for full documentation.

    Args:
        config: Agent configuration path
        **kwargs: Arguments to pass to run_nodes_async

    Returns:
        Dict mapping function names to their results
    """
    return asyncio.run(run_nodes_async(config, **kwargs))

run_nodes_async async

run_nodes_async(
    config: JoinablePathLike | AgentsManifest,
    *,
    module: str | None = None,
    functions: list[str] | None = None,
    inputs: dict[str, Any] | None = None,
    parallel: bool = False,
) -> dict[str, Any]

Execute node functions with dependency handling.

Parameters:

Name Type Description Default
config JoinablePathLike | AgentsManifest

Node configuration (path or manifest)

required
module str | None

Optional module to discover functions from

None
functions list[str] | None

Optional list of function names to run (auto-discovers if None)

None
inputs dict[str, Any] | None

Optional input values for function parameters

None
parallel bool

Whether to run independent functions in parallel

False

Returns:

Type Description
dict[str, Any]

Dict mapping function names to their results

Example
@node_function
async def analyze(analyzer: Agent) -> str:
    return await analyzer.run("...")

results = await run_nodes_async("agents.yml")
print(results["analyze"])
Source code in src/llmling_agent/running/run_nodes.py
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
async def run_nodes_async(
    config: JoinablePathLike | AgentsManifest,
    *,
    module: str | None = None,
    functions: list[str] | None = None,
    inputs: dict[str, Any] | None = None,
    parallel: bool = False,
) -> dict[str, Any]:
    """Execute node functions with dependency handling.

    Args:
        config: Node configuration (path or manifest)
        module: Optional module to discover functions from
        functions: Optional list of function names to run (auto-discovers if None)
        inputs: Optional input values for function parameters
        parallel: Whether to run independent functions in parallel

    Returns:
        Dict mapping function names to their results

    Example:
        ```python
        @node_function
        async def analyze(analyzer: Agent) -> str:
            return await analyzer.run("...")

        results = await run_nodes_async("agents.yml")
        print(results["analyze"])
        ```
    """
    from llmling_agent import AgentPool

    # Find functions to run
    if module:
        discovered = discover_functions(module)
    else:
        # Use calling module
        import inspect

        frame = inspect.currentframe()
        while frame:
            if frame.f_globals.get("__name__") != __name__:
                break
            frame = frame.f_back
        if not frame:
            msg = "Could not determine calling module"
            raise RuntimeError(msg)
        discovered = discover_functions(frame.f_globals["__file__"])

    if functions:
        discovered = [f for f in discovered if f.name in functions]

    # Run with pool
    async with AgentPool[None](config) as pool:
        return await execute_functions(
            discovered,
            pool,
            inputs=inputs,
            parallel=parallel,
        )