一键导入
add-tool
Step-by-step procedure to create a new LangChain tool in a genai-tk project and register it in an agent profile.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Step-by-step procedure to create a new LangChain tool in a genai-tk project and register it in an agent profile.
用 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-tool |
| description | Step-by-step procedure to create a new LangChain tool in a genai-tk project and register it in an agent profile. |
| tags | ["tools","langchain","agents"] |
| version | 1.0 |
Follow these steps to add a new tool that agents can call.
cli initconfig/agents/langchain.yamlCreate <package>/tools/my_tool.py:
"""My custom tool for <purpose>."""
from __future__ import annotations
from langchain_core.tools import BaseTool, tool
from pydantic import Field
# Option A: Simple function tool
@tool
def my_tool(input: str) -> str:
"""One-line description visible to the agent. Be specific about what inputs it expects."""
# Your implementation here
return f"Result: {input}"
# Option B: Class-based tool (for more control, e.g. injected dependencies)
class MyTool(BaseTool):
name: str = "my_tool"
description: str = "Detailed description. Include expected input format."
api_key: str = Field(default="", exclude=True)
def _run(self, input: str) -> str:
return f"Result: {input}"
async def _arun(self, input: str) -> str:
return self._run(input)
# Always provide a factory function for agent profiles to reference
def create_my_tools(api_key: str = "") -> list[BaseTool]:
"""Factory function referenced in agent profile YAML."""
return [MyTool(api_key=api_key)]
In config/agents/langchain.yaml, add to your profile's tools: list:
langchain_agents:
my_agent:
tools:
# Option A: direct function reference
- spec: my_project.tools.my_tool.my_tool
# Option B: factory function (can accept config kwargs)
- spec: my_project.tools.my_tool.create_my_tools
type: factory
kwargs:
api_key: ${oc.env:MY_API_KEY,}
from my_project.tools.my_tool import my_tool
result = my_tool.invoke("test input")
print(result)
cli agents langchain -p my_agent "Use my_tool to process: hello world"
oc.env:VAR in config, inject via factory kwargs_arun if the tool makes I/O calls (HTTP, DB, etc.)| Concern | Path |
|---|---|
| Tool implementation | <package>/tools/<name>.py |
| Agent profile | config/agents/langchain.yaml |
| Tool factory pattern | genai_tk/agents/tools/ (reference examples) |
| Tests | tests/unit_tests/tools/test_<name>.py |