LangChain Reference home pageLangChain ReferenceLangChain Reference
  • GitHub
  • Main Docs
Deep Agents
LangChain
LangGraph
Integrations
LangSmith
  • Overview
    • Overview
    • Caches
    • Callbacks
    • Documents
    • Document loaders
    • Embeddings
    • Exceptions
    • Language models
    • Serialization
    • Output parsers
    • Prompts
    • Rate limiters
    • Retrievers
    • Runnables
    • Utilities
    • Vector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    ⌘I

    LangChain Assistant

    Ask a question to get started

    Enter to send•Shift+Enter new line

    Menu

    OverviewCachesCallbacksDocumentsDocument loadersEmbeddingsExceptionsLanguage modelsSerializationOutput parsersPromptsRate limitersRetrieversRunnablesUtilitiesVector stores
    MCP Adapters
    Standard Tests
    Text Splitters
    Language
    Theme
    Pythonlangchain-corecallbacksbaseLLMManagerMixinon_llm_new_token
    Method●Since v0.1

    on_llm_new_token

    Run on new output token.

    Only available when streaming is enabled.

    For both chat models and non-chat models (legacy text completion LLMs).

    Copy
    on_llm_new_token(
      self,
      token: str,
      *,
      chunk: GenerationChunk | ChatGenerationChunk | None = None,
      run_id: UUID,
      parent_run_id: UUID | None = None,
      tags: list[str] | None = None,
      **kwargs: Any = {}
    ) -> Any

    Parameters

    NameTypeDescription
    token*str

    The new token.

    chunkGenerationChunk | ChatGenerationChunk | None
    Default:None

    The new generated chunk, containing content and other information.

    run_id*UUID

    The ID of the current run.

    parent_run_idUUID | None
    Default:None

    The ID of the parent run.

    tagslist[str] | None
    Default:None

    The tags.

    **kwargsAny
    Default:{}

    Additional keyword arguments.

    View source on GitHub