langchain-1-basic-chain-composition

Sub-skill of langchain: 1. Basic Chain Composition.

5 stars

Best use case

langchain-1-basic-chain-composition is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Sub-skill of langchain: 1. Basic Chain Composition.

Teams using langchain-1-basic-chain-composition 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/1-basic-chain-composition/SKILL.md --create-dirs "https://raw.githubusercontent.com/vamseeachanta/workspace-hub/main/.agents/skills/_archive/ai/prompting/langchain/1-basic-chain-composition/SKILL.md"

Manual Installation

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

How langchain-1-basic-chain-composition Compares

Feature / Agentlangchain-1-basic-chain-compositionStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Sub-skill of langchain: 1. Basic Chain Composition.

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

# 1. Basic Chain Composition

## 1. Basic Chain Composition


**Simple LLM Chain:**
```python
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser

def create_simple_chain(
    model: str = "gpt-4",
    temperature: float = 0.7
):
    """
    Create a simple prompt-model-output chain.

    Args:
        model: Model name to use
        temperature: Sampling temperature

    Returns:
        Runnable chain that accepts dict input
    """
    # Define prompt template
    prompt = ChatPromptTemplate.from_messages([
        ("system", "You are a helpful assistant specializing in {domain}."),
        ("human", "{question}")
    ])

    # Initialize LLM
    llm = ChatOpenAI(model=model, temperature=temperature)

    # Create chain with LCEL (LangChain Expression Language)
    chain = prompt | llm | StrOutputParser()

    return chain

# Usage
chain = create_simple_chain(model="gpt-4", temperature=0.3)

response = chain.invoke({
    "domain": "marine engineering",
    "question": "What are the key factors in mooring system design?"
})

print(response)
```

**Sequential Chain with Multiple Steps:**
```python
from langchain_core.runnables import RunnablePassthrough, RunnableParallel
from langchain_core.prompts import ChatPromptTemplate
from langchain_openai import ChatOpenAI
from langchain_core.output_parsers import StrOutputParser

def create_analysis_chain():
    """
    Create a multi-step analysis chain:
    1. Extract key points
    2. Analyze implications
    3. Generate recommendations
    """
    llm = ChatOpenAI(model="gpt-4", temperature=0.3)

    # Step 1: Extract key points
    extract_prompt = ChatPromptTemplate.from_template(
        "Extract the 5 most important points from this text:\n\n{text}\n\nKey Points:"
    )

    # Step 2: Analyze implications
    analyze_prompt = ChatPromptTemplate.from_template(
        "Based on these key points:\n{key_points}\n\n"
        "What are the main implications and potential risks?"
    )

    # Step 3: Generate recommendations
    recommend_prompt = ChatPromptTemplate.from_template(
        "Given these key points:\n{key_points}\n\n"
        "And this analysis:\n{analysis}\n\n"
        "Provide 3-5 actionable recommendations."
    )

    # Build chain
    chain = (
        {"text": RunnablePassthrough()}
        | RunnableParallel(
            text=RunnablePassthrough(),
            key_points=extract_prompt | llm | StrOutputParser()
        )
        | RunnableParallel(
            key_points=lambda x: x["key_points"],
            analysis=analyze_prompt | llm | StrOutputParser()
        )
        | recommend_prompt
        | llm
        | StrOutputParser()
    )

    return chain

# Usage
analysis_chain = create_analysis_chain()

document_text = """
The offshore wind farm project faces several challenges including
supply chain delays, regulatory approval processes, and environmental
impact assessments. Budget overruns of 15% have been reported...
"""

recommendations = analysis_chain.invoke(document_text)
print(recommendations)
```

Related Skills

issue-tree-decomposition

5
from vamseeachanta/workspace-hub

Break a large umbrella GitHub issue into a layered tree of focused follow-on issues using read-only subagent analysis, then create the issues locally and update docs/parent issue with the issue map.

skill-chain-context-optimization

5
from vamseeachanta/workspace-hub

Refactor large or frequently-run skills into context-efficient chains using isolated execution, file-backed handoffs, minimal summaries, and runtime-aware command substitution.

mkdocs-basic-code-block

5
from vamseeachanta/workspace-hub

Sub-skill of mkdocs: Basic Code Block.

web-artifacts-builder-basic-template

5
from vamseeachanta/workspace-hub

Sub-skill of web-artifacts-builder: Basic Template.

usage-tracker-1-basic-usage-logging

5
from vamseeachanta/workspace-hub

Sub-skill of usage-tracker: 1. Basic Usage Logging (+1).

parallel-batch-executor-1-basic-parallel-execution-with-xargs

5
from vamseeachanta/workspace-hub

Parallel batch processing with xargs. Use when running commands concurrently over a list of items with controlled parallelism.

interactive-menu-builder-1-basic-menu-structure

5
from vamseeachanta/workspace-hub

Sub-skill of interactive-menu-builder: 1. Basic Menu Structure.

docker-1-basic-dockerfile-patterns

5
from vamseeachanta/workspace-hub

Sub-skill of docker: 1. Basic Dockerfile Patterns.

github-actions-1-basic-workflow-structure

5
from vamseeachanta/workspace-hub

Sub-skill of github-actions: 1. Basic Workflow Structure.

airflow-1-basic-dag-structure

5
from vamseeachanta/workspace-hub

Sub-skill of airflow: 1. Basic DAG Structure.

activepieces-1-basic-flow-structure

5
from vamseeachanta/workspace-hub

Sub-skill of activepieces: 1. Basic Flow Structure.

orcawave-damping-sweep-total-damping-composition

5
from vamseeachanta/workspace-hub

Sub-skill of orcawave-damping-sweep: Total Damping Composition (+1).