langchain-6-streaming-responses

Sub-skill of langchain: 6. Streaming Responses.

5 stars

Best use case

langchain-6-streaming-responses is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Sub-skill of langchain: 6. Streaming Responses.

Teams using langchain-6-streaming-responses should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/6-streaming-responses/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/_archive/ai/prompting/langchain/6-streaming-responses/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/6-streaming-responses/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How langchain-6-streaming-responses Compares

Feature / Agentlangchain-6-streaming-responsesStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Sub-skill of langchain: 6. Streaming Responses.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

SKILL.md Source

# 6. Streaming Responses

## 6. Streaming Responses


**Streaming Chain:**
```python
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
import asyncio

def create_streaming_chain():
    """Create chain that supports streaming output."""

    llm = ChatOpenAI(
        model="gpt-4",
        temperature=0.7,
        streaming=True
    )

    prompt = ChatPromptTemplate.from_template(
        "You are an expert engineer. Explain in detail: {topic}"
    )

    chain = prompt | llm | StrOutputParser()

    return chain

# Synchronous streaming
def stream_response(chain, topic: str):
    """Stream response token by token."""
    print("Response: ", end="", flush=True)

    for chunk in chain.stream({"topic": topic}):
        print(chunk, end="", flush=True)

    print("\n")

# Async streaming
async def astream_response(chain, topic: str):
    """Async stream response."""
    print("Response: ", end="", flush=True)

    async for chunk in chain.astream({"topic": topic}):
        print(chunk, end="", flush=True)

    print("\n")

# Usage
chain = create_streaming_chain()

# Sync streaming
stream_response(chain, "mooring line catenary equations")

# Async streaming
asyncio.run(astream_response(chain, "wave-structure interaction"))
```

**Streaming with Callbacks:**
```python
from langchain_openai import ChatOpenAI
from langchain_core.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from langchain_core.callbacks.base import BaseCallbackHandler
from typing import Any, Dict, List
import json

class CustomStreamHandler(BaseCallbackHandler):
    """Custom callback handler for streaming."""

    def __init__(self):
        self.tokens = []
        self.final_response = ""

    def on_llm_new_token(self, token: str, **kwargs) -> None:
        """Called when a new token is generated."""
        self.tokens.append(token)
        self.final_response += token
        # Could send to WebSocket, write to file, etc.
        print(token, end="", flush=True)

    def on_llm_end(self, response: Any, **kwargs) -> None:
        """Called when LLM finishes."""
        print(f"\n\n[Generation complete: {len(self.tokens)} tokens]")

    def on_llm_error(self, error: Exception, **kwargs) -> None:
        """Called on error."""
        print(f"\n[Error: {error}]")

def stream_with_callbacks(prompt: str):
    """Stream with custom callbacks."""

    handler = CustomStreamHandler()

    llm = ChatOpenAI(
        model="gpt-4",
        temperature=0.7,
        streaming=True,
        callbacks=[handler]
    )

    response = llm.invoke(prompt)

    return handler.final_response, handler.tokens

# Usage
response, tokens = stream_with_callbacks(
    "Explain the design considerations for a turret mooring system"
)

print(f"\nTotal tokens: {len(tokens)}")
```

Related Skills

canned-responses

5
from vamseeachanta/workspace-hub

Generate templated responses for common legal inquiries and identify when situations require individualized attention

openpyxl-5-large-dataset-handling-with-streaming

5
from vamseeachanta/workspace-hub

Sub-skill of openpyxl: 5. Large Dataset Handling with Streaming.

rag-system-builder-streaming-responses

5
from vamseeachanta/workspace-hub

Sub-skill of rag-system-builder: Streaming Responses.

canned-responses-use-when

5
from vamseeachanta/workspace-hub

Sub-skill of canned-responses: Use When (+6).

canned-responses-escalation-triggers-all-categories

5
from vamseeachanta/workspace-hub

Sub-skill of canned-responses: Universal Escalation Triggers (Apply to All Categories) (+2).

canned-responses-template-organization

5
from vamseeachanta/workspace-hub

Sub-skill of canned-responses: Template Organization (+1).

canned-responses-step-1-define-the-use-case

5
from vamseeachanta/workspace-hub

Sub-skill of canned-responses: Step 1: Define the Use Case (+6).

canned-responses-required-customization

5
from vamseeachanta/workspace-hub

Sub-skill of canned-responses: Required Customization (+2).

canned-responses-1-data-subject-requests-dsrs

5
from vamseeachanta/workspace-hub

Sub-skill of canned-responses: 1. Data Subject Requests (DSRs) (+6).

langchain-rate-limit-errors

5
from vamseeachanta/workspace-hub

Sub-skill of langchain: Rate Limit Errors (+2).

langchain-5-document-processing

5
from vamseeachanta/workspace-hub

Sub-skill of langchain: 5. Document Processing.

langchain-4-rag-retrieval-augmented-generation

5
from vamseeachanta/workspace-hub

Sub-skill of langchain: 4. RAG (Retrieval Augmented Generation).