원클릭으로
add-chain
Step-by-step procedure to create a new LangChain LCEL chain in a genai-tk project.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Step-by-step procedure to create a new LangChain LCEL chain in a genai-tk project.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
Build or modify LangChain, DeepAgent, DeerFlow profiles, agent tools, middleware, checkpointing, skills wiring, and the shared harness layer in genai-tk.
Work on BAML structured extraction, BAML CLI commands, processors, utilities, and Prefect BAML workflow integration in genai-tk.
Work on browser automation, sandbox browser tools, direct Playwright tools, AioSandbox backend, and sandbox CLI support in genai-tk.
Add or modify genai-tk Typer CLI commands, dynamic command registration, project scaffolding, and generated Copilot/agent support files.
Work on genai-tk OmegaConf configuration, profiles, overrides, env substitution, and config discovery. Use when editing config/*.yaml or genai_tk.config_mgmt.config_mngr.
Work on core LLM, embeddings, vector store, provider, cache, prompt, and retriever factories in genai-tk. Use when editing genai_tk/core or provider configuration.
| name | add-chain |
| description | Step-by-step procedure to create a new LangChain LCEL chain in a genai-tk project. |
Follow these steps to add a new LangChain Expression Language (LCEL) chain to a genai-tk project.
cli init<package>/chains/ directoryCreate a new file in <package>/chains/my_chain.py:
"""My custom chain — describe what it does."""
from genai_tk.core.factories.llm_factory import get_llm
from genai_tk.core.prompts import def_prompt
from langchain_core.output_parsers import StrOutputParser
from langchain_core.runnables import Runnable
def get_chain(config: dict | None = None) -> Runnable:
"""Create the chain: prompt | llm | parser."""
llm = get_llm()
prompt = def_prompt(
system="You are an expert at [domain]. Be concise and accurate.",
user="{input}",
)
return prompt | llm | StrOutputParser()
uv run cli core run "My Chain" "example input"
Launch make webapp and navigate to the Runnable Playground page. The chain will appear in the dropdown.
from <package_name>.chains.my_chain import get_chain
chain = get_chain()
result = chain.invoke({"input": "test"})
print(result)
from langchain_core.runnables import RunnablePassthrough
chain = (
{"context": retriever, "question": RunnablePassthrough()}
| prompt
| llm
| StrOutputParser()
)
from langchain_core.runnables import RunnableBranch
chain = RunnableBranch(
(lambda x: "math" in x["topic"], math_chain),
(lambda x: "code" in x["topic"], code_chain),
default_chain,
)
from pydantic import BaseModel
class Answer(BaseModel):
reasoning: str
answer: str
confidence: float
chain = prompt | llm.with_structured_output(Answer)
from genai_tk.core.factories.llm_factory import get_llm
from genai_tk.core.factories.embeddings_factory import get_embeddings_store
store = get_embeddings_store()
retriever = store.as_retriever(search_kwargs={"k": 4})
rag_chain = (
{"context": retriever, "question": RunnablePassthrough()}
| def_prompt(
system="Answer based on the context provided.",
user="Context: {context}\n\nQuestion: {question}",
)
| get_llm()
| StrOutputParser()
)
register_runnable(
RunnableItem(
tag="Category", # Groups chains in the UI
name="Display Name", # Unique name for the chain
runnable=get_chain, # Factory function returning a Runnable
examples=[ # Example inputs for the playground
Example(query=["input 1"]),
Example(query=["input 2"]),
],
)
)