Skip to content

feat(llm): carry a per-node invocation policy and report time to first token - #294

Draft
lin-snow wants to merge 1 commit into
mainfrom
feat/llm-invocation-policy
Draft

lin-snow wants to merge 1 commit into
mainfrom
feat/llm-invocation-policy

Conversation

@lin-snow

@lin-snow lin-snow commented Sep 10, 2026 •

Copy link
Copy Markdown
Contributor

Important

  1. Make sure you have read our contribution guidelines
  2. Search existing issues and pull requests to confirm this change is not a duplicate
  3. Open or identify the issue this pull request resolves or advances
  4. Use a Conventional Commits title for this pull request, and mark breaking changes with !
  5. Remember that the pull request title will become the squash merge commit message
  6. If CLA Assistant prompts you, sign CLA.md in the pull request conversation

Related Issue

Closes #293

Summary

Adds an invocation block to LLM-family node data, and publishes the time-to-first-token the LLM node already measures as node execution metadata.

invocation is a sibling of model, not part of completion_params. A per-node first-token budget is being threaded through the Dify plugin chain, and completion_params is the wrong home for it: that dictionary is forwarded to model providers verbatim, so every consumer needs a defensive pop, and the value shows up in exported DSL next to temperature as if the provider understood it.

data:
  model: { provider: openai, name: gpt-4o, mode: chat, completion_params: {} }
  invocation:
    first_token_timeout_ms: 2000

first_token_timeout_ms is an optional positive integer; absent means no budget. The block exposes it as first_token_timeout in seconds, which is the unit every hop below graphon works in — milliseconds are the DSL and UI unit only, and this is the single place the conversion happens.

LLMNodeData and QuestionClassifierNodeData get the block. ParameterExtractorNodeData deliberately does not: that node invokes with stream=False, where a single result arrives only once generation has finished, so a first-token budget there would quietly become a total-generation budget.

graphon carries the value and enforces nothing. It is read off the node data by the host adapter, which owns the transport. In particular this adds no parameter to LLMProtocol — that would hand every adapter that cannot honour it one more argument with no effect, which is the shape TD-06 already tracks. Closed PR #212 attempted exactly that and its own compatibility table shows the cost: any implementation without the keyword and without **kwargs raises TypeError on every LLM call, forcing an ordering constraint on the host's pin bump. Keeping graphon a carrier removes that constraint.

The second change is smaller. LLMNode already measures TTFT into LLMUsage.time_to_first_token but never surfaced it per node, so an operator had no number to base a budget on. It now writes WorkflowNodeExecutionMetadataKey.TIME_TO_FIRST_TOKEN alongside the existing token and price keys, and omits the key entirely when no content streamed rather than recording a null.

Both changes are additive and optional. Workflows saved before this deserialize unchanged, and a host that ignores invocation behaves exactly as it does today.

Checklist

  • This pull request links the issue it resolves or advances
  • This pull request title follows Conventional Commits, and any breaking change is marked with !
  • If CLA Assistant prompted me, I signed CLA.md in the pull request conversation

…t token

Adds an `invocation` block to LLM and question-classifier node data, a sibling
of `model`, holding per-node policy about how a model is called rather than what
is asked of it. Its only setting today is `first_token_timeout_ms`.

It exists because the host has nowhere else to put a first-token timeout.
`ModelConfig.completion_params` is forwarded to model providers verbatim, so a
host-internal setting there needs a defensive pop at every consumer, one
forgotten pop sends an unknown argument to a provider, and the value lands in
exported DSL next to `temperature` as if the provider understood it.

The block exposes the value in seconds as `first_token_timeout`, which is the
unit every hop below graphon works in; milliseconds are the DSL and UI unit
only, and this is the single place the conversion happens. The field carries no
alias, because `Node.validate_node_data` dumps by name on every construction and
an alias would silently drop the value there.

The parameter extractor deliberately has no block. It invokes with
`stream=False`, where the single result arrives once generation has finished, so
a first-token timeout would quietly become a total-generation timeout.

graphon carries the value and enforces nothing; the host reads it off the node
data. No argument is added to `LLMProtocol` -- that would hand every adapter
that cannot honour it one more argument with no effect, which is the shape
TD-06 already tracks, and it would make any host lacking the keyword fail on
every LLM call. PR #212 took that route; keeping graphon a carrier means no host
has to move first.

Separately, `LLMNode` now publishes the time to first token it already measures
into `LLMUsage`, under a new `TIME_TO_FIRST_TOKEN` metadata key, so an operator
has a number to base a timeout on. A run that streamed no content omits the key
rather than recording a null; a genuine 0.0 is still published.

Both changes are additive and optional. Workflows saved before this deserialize
unchanged.

Closes #293

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Carry a per-node invocation policy in LLM node data, and report node time-to-first-token

1 participant