Sign in

    workgraph-llm

    Runtime-independent typed LLM nodes for workgraph

    agent
    graph
    llm
    moonbit
    Download zip
    Author
    Version
    0.1.4
    License
    MIT
    Last updated
    2 months ago
    Downloads
    23

    #moonbit: import: - path: mizchi/llm@0.3.1 alias: llm - path: moonbitlang/async@0.21.0 alias: async - path: totto2727/workgraph-core@0.1.4 alias: core - path: totto2727/workgraph-llm@0.1.4 alias: workgraph_llm backend: native

    #workgraph-llm

    workgraph-llm owns the provider-neutral adapter from mizchi/llm messages, tools, streamed events, and collected results to typed Workgraph nodes. For shared installation and graph construction, see the root Setup and Usage.

    #Usage

    Run an LLM node with a deterministic provider and observe its response in graph state:

    ///|
    async test "workgraph-llm response usage" {
    let entry = @core.NodeId::NodeId("llm")
    let provider = @llm.MockProvider::new([
    [
    @llm.MessageStart,
    @llm.TextDelta("Use a typed node"),
    @llm.MessageEnd(finish_reason=@llm.Stop, usage=None),
    ],
    ]).boxed()
    let node = @workgraph_llm.llm_node(
    entry,
    @core.NodeMetadata::NodeMetadata(
    name="LLM",
    description=None,
    kind=@core.Llm,
    tags=[],
    ),
    @workgraph_llm.LlmNodeSpec::LlmNodeSpec(
    provider,
    fn(_context, prompt : String) {
    @workgraph_llm.LlmRequest::LlmRequest([@llm.Message::user(prompt)])
    },
    fn(_state, response) {
    @core.NodeOutput::NodeOutput(Some(response.text), None)
    },
    ),
    )
    let definition = @core.GraphDefinition::GraphDefinition(
    @core.Reducer::Reducer(fn(_state : String, patch : String) { patch }),
    )
    definition.add_node(node)
    definition.set_router(
    entry,
    @core.router([], fn(_state, _completion) { @core.End }),
    )
    definition.set_entry(entry)
    let result = @core.GraphRuntime::GraphRuntime(definition.compile()).invoke(
    "Plan the next step",
    )
    inspect(result.final_state, content="Use a typed node")
    inspect(result.steps, content="1")
    }

    The checked LLM example also reports collected token usage.

    #API

    This README was generated from the share-artifact skill and README template.

    LlmNodeError

    pub suberror LlmNodeError {
    ProviderFailed(String)
    } derive(
    Debug
    )

    Raised when an LLM provider reports a stream failure.

    LlmNodeSpec

    LlmNodeSpec::LlmNodeSpec

    Creates a provider-backed LLM graph-node specification.

    LlmRequest

    pub(all) struct LlmRequest {
    messages : Array[
    Message
    ]
    tools : Array[
    ToolDef
    ]
    }

    A provider-neutral request built from mizchi/llm message and tool types.

    LlmRequest::LlmRequest

    Creates one LLM invocation request.

    llm_node

    Creates a graph node that builds a request, invokes its provider, and decodes the collected response.

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io