langchain_core.callbacks.manager.atrace_as_chain_groupΒΆ

langchain_core.callbacks.manager.atrace_as_chain_group(group_name: str, callback_manager: Optional[AsyncCallbackManager] = None, *, inputs: Optional[Dict[str, Any]] = None, project_name: Optional[str] = None, example_id: Optional[Union[str, UUID]] = None, run_id: Optional[UUID] = None, tags: Optional[List[str]] = None, metadata: Optional[Dict[str, Any]] = None) AsyncGenerator[AsyncCallbackManagerForChainGroup, None][source]ΒΆ

Get an async callback manager for a chain group in a context manager. Useful for grouping different async calls together as a single run even if they aren’t composed in a single chain.

Parameters
  • group_name (str) – The name of the chain group.

  • callback_manager (AsyncCallbackManager, optional) – The async callback manager to use, which manages tracing and other callback behavior.

  • project_name (str, optional) – The name of the project. Defaults to None.

  • example_id (str or UUID, optional) – The ID of the example. Defaults to None.

  • run_id (UUID, optional) – The ID of the run.

  • tags (List[str], optional) – The inheritable tags to apply to all runs. Defaults to None.

  • metadata (Dict[str, Any], optional) – The metadata to apply to all runs. Defaults to None.

  • inputs (Optional[Dict[str, Any]]) –

Returns

The async callback manager for the chain group.

Return type

AsyncCallbackManager

Note: must have LANGCHAIN_TRACING_V2 env var set to true to see the trace in LangSmith.

Example

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