Channels

Purpose and Scope

Channels are the boundary where an agent conversation, an external communication surface, and the credentials needed to act on that surface meet. In the LangChain core source, a chat session is explicitly described as a single conversation, channel, or other group of messages, so the term is intentionally broader than a transcript and more specific than an entire application. Treat a channel as the durable addressable place where messages, tool affordances, and provider access come together. That framing helps application developers decide what can be shown to a model, what must stay in control-plane storage, and what should be checked before enabling actions. Sources: libs/core/langchain_core/chat_sessions.py

This page explains channels through the official Auth Service V2 Slack token check and the Python primitives that model related behavior in this repository. The official endpoint answers a narrow question: whether a workspace has Slack token material available. It does not return the token, refresh token, channel metadata, user identity, or message history. The repository source then shows how LangChain keeps comparable concerns separated: chat state is represented as messages and function specifications, OAuth helpers isolate token management from model invocation, and provider tests normalize credentials into transport headers rather than visible URLs. Sources: libs/core/langchain_core/chat_sessions.py, libs/partners/openai/langchain_openai/chatgpt_oauth.py, libs/partners/ollama/tests/unit_tests/test_auth.py

A practical mental model is to distinguish channels, connections, and sessions. A channel is the conversation surface, such as a Slack workspace or conversation that an agent may act in. A connection is the authorization and provider configuration that makes the channel usable. A session is the runtime grouping of messages and operations associated with work in that channel. The supplied source does not implement Slack itself, but it provides the same design vocabulary: message groups in core, OAuth token providers in partner code, and create, update, and close session tool names in the classic compatibility layer. Sources: libs/core/langchain_core/chat_sessions.py, libs/langchain/langchain_classic/tools/multion/create_session.py, libs/langchain/langchain_classic/tools/multion/update_session.py, libs/langchain/langchain_classic/tools/multion/close_session.py

Relevant Source Files

  • libs/core/langchain_core/chat_sessions.py — Defines ChatSession as a typed dictionary for messages and function specs, and explicitly describes a chat session as a conversation, channel, or group of messages.
  • libs/partners/openai/langchain_openai/chatgpt_oauth.py — Implements provider-specific ChatGPT OAuth helpers with token constants, default storage, token validation, refresh behavior, and a clear separation between login/token management and model invocation.
  • libs/langchain/langchain_classic/tools/multion/create_session.py — Re-exports legacy MultionCreateSession and CreateSessionSchema through a deprecated import lookup, preserving a session-creation tool surface.
  • libs/langchain/langchain_classic/tools/multion/update_session.py — Re-exports legacy MultionUpdateSession and UpdateSessionSchema, preserving a session-update surface for ongoing external interactions.
  • libs/langchain/langchain_classic/tools/multion/close_session.py — Re-exports legacy MultionCloseSession and CloseSessionSchema, preserving a close-session surface for ending external interactions.
  • libs/partners/ollama/tests/unit_tests/test_auth.py — Tests URL credential parsing and Basic authorization header generation for Ollama clients, demonstrating expected handling of provider endpoint authentication.

Core Primitives

The smallest repository primitive for this page is ChatSession. It is a typed dictionary with optional messages and functions fields. The messages field contains a sequence of LangChain chat messages loaded from a source, while the functions field contains function-calling specifications associated with those messages. This compact structure is important because it keeps channel state provider-neutral. A Slack channel, browser automation session, or hosted chat UI can all be represented to the model as ordered messages plus available callable capabilities, without embedding the credential or transport details that make a provider request possible. Sources: libs/core/langchain_core/chat_sessions.py

Credential handling appears in a separate provider layer. The ChatGPT OAuth helper module documents that it implements authorization-code and device-style token flows, a file-backed token store, and refresh logic for a provider-specific subscription-auth scenario. Its module documentation says these helpers exist to keep login and token management separate from model invocation, and that the model-facing class consumes a token provider rather than directly managing OAuth. For channel implementations, that is the key architectural rule: a model call should receive messages and tool schemas, while token checks, token refreshes, and token revocation happen outside prompt construction. Sources: libs/partners/openai/langchain_openai/chatgpt_oauth.py

The token type in the OAuth helper reinforces that boundary. The token bundle stores access and refresh tokens, validates that required secrets are non-empty, requires a timezone-aware expiry, and excludes secret-bearing fields from its default representation. Even though this helper targets ChatGPT subscription auth rather than Slack, it illustrates how provider integrations should treat channel credentials as sensitive runtime state. A channel can be visible in logs, UI routing, and message history; its credential material should not be. This distinction is especially relevant for Auth Service V2 endpoints whose purpose is to confirm presence or revoke access, not to expose secrets. Sources: libs/partners/openai/langchain_openai/chatgpt_oauth.py

Session-oriented tools show the lifecycle side of channel work. The classic Multion modules dynamically look up deprecated community tool classes for creating, updating, and closing sessions. These files are compatibility shims rather than preferred new implementations, but their public names still describe the operations many channel integrations need. A remote surface is opened, updated as the agent takes actions or receives new state, and closed when the work is complete. That lifecycle maps naturally to Slack and similar channels: preflight token state, create or resume a session, perform tool-backed actions, then end or disconnect when the workflow is no longer active. Sources: libs/langchain/langchain_classic/tools/multion/create_session.py, libs/langchain/langchain_classic/tools/multion/update_session.py, libs/langchain/langchain_classic/tools/multion/close_session.py

Auth Service V2 API Components

The channel-facing Slack check is intentionally small. A client calls the workspace Slack token existence endpoint and receives a successful JSON response with a required boolean field named has_token. The field answers whether Slack-authenticated behavior can be enabled for the workspace; it is not a bearer credential and should not be treated as proof that any individual Slack action will succeed. Use it as a preflight signal for UI state, agent routing, and tool availability. If it returns false, present a connection or authorization path instead of letting the agent discover the failure through repeated tool calls.

curl --request GET --url https://api.example.com/v2/auth/tokens/workspace/slack/exists
{
  "has_token": true
}

The surrounding Auth Service V2 endpoints define the rest of the operational shape. The batch check endpoint accepts a required array of provider identifiers and returns a provider-to-boolean token presence map for the current user. That is useful when rendering a broader provider picker or deciding which integrations to expose in an agent setup screen. The workspace Slack revoke endpoint removes Slack tokens for the workspace. Together, the check, batch check, and revoke operations support a clean product loop: discover whether access exists, expose only the relevant capabilities, and remove access when the workspace disconnects Slack.

System-to-Code Mapping

At runtime, a channel-aware LangChain application usually has three layers. The application layer renders or routes to the external surface, such as Slack. The state layer stores the conversation and callable function specifications, which the core ChatSession shape models as messages and functions. The authorization layer answers token-presence questions and prepares authenticated transport for provider-specific requests. Keeping those layers separate gives developers safer defaults: the application can show a Slack channel name, the model can reason over messages and tool descriptions, and integration code can attach credentials only when a request actually leaves the process. Sources: libs/core/langchain_core/chat_sessions.py, libs/partners/openai/langchain_openai/chatgpt_oauth.py

The Ollama authentication tests make this separation observable in a small but concrete way. They verify that missing authentication input produces no URL or headers, that URLs without credentials remain unchanged, and that host-and-port strings without a scheme are accepted by adding an HTTP scheme. They also verify that embedded user credentials are removed from the cleaned URL and converted into an authorization header, including cases with paths, query strings, fragments, and percent-encoded special characters. The same safety property applies to channels: credentials should become transport configuration, not channel identifiers or message text. Sources: libs/partners/ollama/tests/unit_tests/test_auth.py

Execution Flow

A typical Slack channel preflight should happen before the model is invoked. First, the client checks whether workspace Slack tokens exist. If the response says no token is present, the application can disable Slack-specific tools, render a connection prompt, or route the user to an authorization flow. If the response says a token exists, the application can load or construct the relevant conversation state, attach safe tool schemas, and let the agent reason over the user-visible messages. The model should not receive the Slack token, a refresh token, or a URL containing embedded credentials.

When a provider request is needed, perform the credential operation in integration code. The ChatGPT OAuth helper shows a stateful pattern with defaults for redirect handling, scopes, refresh skew, and file-backed token storage. The Ollama tests show a stateless parsing pattern where credentials in a base URL become headers while the cleaned URL remains safe to pass around. Both styles support the same channel execution model: check authorization in the control plane, represent conversation state with message structures, and give the model only the tool interfaces required to complete the task. Sources: libs/partners/openai/langchain_openai/chatgpt_oauth.py, libs/partners/ollama/tests/unit_tests/test_auth.py

A useful failure-handling rule is to treat token existence as a current capability signal, not as a permanent entitlement. A true response can become stale if the workspace revokes Slack access, if provider-side policy changes, or if an individual downstream call fails. Your application should therefore keep the preflight close to the action it enables, handle provider errors normally, and refresh visible UI state after revocation. For long-running agents, store enough channel state to resume the conversation, but re-check authorization before executing new Slack actions after a pause or reconnect.

Implementation Notes and Next Steps

When implementing channels, keep three records distinct in your application model. Store the public channel or workspace identifier in your product database, store the conversation as messages and function specifications or another compatible session representation, and use Auth Service V2 to determine whether provider credentials are currently available. If a user disconnects Slack, call the documented workspace revoke endpoint, stop advertising Slack tools, and require the existence check to return true before re-enabling Slack-capable behavior. This keeps channel continuity available without allowing stale credentials to leak into prompts or logs.

For repository-level extension work, prefer current provider packages and core abstractions over classic compatibility imports. The Multion files are informative because they preserve recognizable lifecycle names, but their dynamic deprecated lookup indicates compatibility rather than a recommended implementation location. Continue with the Agent Connections API page to understand provider authorization workflows, Sessions and Chat History for persistent conversation state, Tools for model-callable capabilities, and Deployment and Auth for the larger production boundary around hosted agents and token control. Sources: libs/langchain/langchain_classic/tools/multion/create_session.py, libs/langchain/langchain_classic/tools/multion/update_session.py, libs/langchain/langchain_classic/tools/multion/close_session.py