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-corecallbacksmanagertrace_as_chain_group
    Function●Since v0.1

    trace_as_chain_group

    Get a callback manager for a chain group in a context manager.

    Useful for grouping different calls together as a single run even if they aren't composed in a single chain.

    Copy
    trace_as_chain_group(
      group_name: str,
      callback_manager: CallbackManager | None = None,
      *,
      inputs: dict[str, Any] | None = None,
      project_name: str | None = None,
      example_id: str | UUID | None = None,
      run_id: UUID | None = None,
      tags: list[str] | None = None,
      metadata: dict[str, Any] | None = None
    ) -> Generator[CallbackManagerForChainGroup, None, None]

    Must have LANGCHAIN_TRACING_V2 env var set to true to see the trace in LangSmith.

    Example:

    llm_input = "Foo"
    with trace_as_chain_group("group_name", inputs={"input": llm_input}) as manager:
        # Use the callback manager for the chain group
        res = llm.invoke(llm_input, {"callbacks": manager})
        manager.on_chain_end({"output": res})

    Parameters

    NameTypeDescription
    group_name*str

    The name of the chain group.

    callback_managerCallbackManager | None
    Default:None

    The callback manager to use.

    inputsdict[str, Any] | None
    Default:None

    The inputs to the chain group.

    project_namestr | None
    Default:None

    The name of the project.

    example_idstr | UUID | None
    Default:None

    The ID of the example.

    run_idUUID | None
    Default:None

    The ID of the run.

    tagslist[str] | None
    Default:None

    The inheritable tags to apply to all runs.

    metadatadict[str, Any] | None
    Default:None

    The metadata to apply to all runs.

    View source on GitHub