Agent 生成器
- 作者仓库星标 0
- 作者更新于 实时读取
- 作者仓库 skills-registry
- 领域
- AI 智能
- 兼容 Agent
-
- Claude Code
- Cursor
- Cline
- Codex
- Windsurf
- Gemini CLI
- +20
- 信任分
- 88 / 100 · 社区维护
- 作者 / 版本 / 许可
- @tomevault-io · 未声明 license
- Token 消耗评级
- 较高消耗
- 接入复杂程度
- 需手动接入
- 是否需要外部 API Key
- 需要 · Vendor-specific
- 兼容的系统
- Windows
- 底层运行要求
- Node.js · Python
- 文件与系统权限
-
- 只读
- 允许写入 / 修改
- Shell 执行
- 网络行为
- 允许外网请求
- 安装命令数
- 26 条
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
---
name: ai-agent-builder
description: Principal AI Architect. LangChain/LangGraph (chains, agents, tools, memory), CrewAI (orchestrati…
category: AI 智能
runtime: Node.js / Python
---
# ai-agent-builder 输出预览
## PART A: 任务判断
- 适用问题:提示词、Agent 工作流、模型评估或自动化推理。
- 输入要求:目标材料、限制条件、期望输出和验收方式。
- 证据边界:围绕“Overview / Agent Architecture Patterns / Pattern 1: Linear Chain (Deterministic)”读取原文规则,不把推断写成作者承诺。
## PART B: 执行结果
- **01** 任务判断:确认你的需求是否属于提示词、Agent 工作流、模型评估或自动化推理,并标出输入、限制和预期结果。
- **02** 执行计划:优先按“Overview / Agent Architecture Patterns / Pattern 1: Linear Chain (Deterministic)”拆成步骤,说明每一步会读取什么、修改什么、产出什么。
- **03** 交付结果:给出可复制的命令、文件改动、检查清单或内容草稿,并说明如何继续迭代。
- **04** 风险边界:结合 读取文件、写入/修改文件、执行终端命令、会按任务需要访问外部网络、需要准备 Vendor-specific API Key 给出执行前确认项。
## Running Rules
- 读取文件、写入/修改文件、执行终端命令;会按任务需要访问外部网络;需要准备 Vendor-specific API Key。
- 先小样例验证,再放大到真实任务。
- 交付时同时给结果、检查口径和下一步迭代建议。 原文没有稳定的斜杠命令要求。安装验证后通常全局生效,直接在对话里点名这个 Skill 并描述任务即可。
告诉 Agent 目标文件或材料、期望结果、不可改范围、是否允许联网或执行命令。本 Skill 的权限画像是:读取文件、写入/修改文件、执行终端命令。
先用一个小任务确认它会围绕“Overview / Agent Architecture Patterns / Pattern 1: Linear Chain (Deterministic)”工作;涉及文件或命令时,先看 diff、日志、预览或测试结果。
检查最终产物是否包含明确结果、必要证据和下一步动作;如果输出泛泛而谈,就补充输入、边界和验收标准后重跑。
---
name: ai-agent-builder
description: Principal AI Architect. LangChain/LangGraph (chains, agents, tools, memory), CrewAI (orchestrati…
category: AI 智能
source: tomevault-io/skills-registry
---
# ai-agent-builder
## 什么时候使用
- 把 AI / Agent方向的常用动作沉淀成 Agent 可调用的技能 适合处理AI Agent、提示词、模型评估与自动化推理,核心价值是把输入、判断、执行、验证和交付边界固定下来,避免 Agent 泛泛回答。 把任务拆成可执行、可检查…
- 面向提示词、Agent 工作流、模型评估或自动化推理,优先处理能明确输入、步骤和验收标准的工作。
## 需要提供什么
- 目标材料、目录范围、期望结果和不可改动内容。
- 是否允许联网、执行命令、读写文件或调用外部服务。
## 执行规则
- 围绕「Overview / Agent Architecture Patterns / Pattern 1: Linear Chain (Deterministic)」组织步骤,不把推断写成作者事实。
- 读取文件、写入/修改文件、执行终端命令;会按任务需要访问外部网络;需要准备 Vendor-specific API Key。
- 先跑小样例,确认结果可检查后再扩大任务范围。
## 输出要求
- 给出最终产物、关键证据、验证方式和下一步动作。
- 信息不足时标记 unknown,不编造命令、平台或依赖。 作者原文负责流程事实;仓库文件负责来源和命令;流狐只补充适用场景、限制和质量判断。
skill "ai-agent-builder" {
输入层 -> 用户目标 + 目标文件 + 禁止范围 + 验收标准
上下文层 -> Overview / Agent Architecture Patterns / Pattern 1: Linear Chain (Deterministic)
规则层 -> SKILL.md 触发条件 / 执行顺序 / 输出格式
运行层 -> Node.js / Python | 读取文件、写入/修改文件、执行终端命令 | 会按任务需要访问外部网络
安全层 -> 需要准备 Vendor-specific API Key + 小任务验证 + diff / 日志复核
输出层 -> 可复制结果 + 检查清单 + 下一步迭代
} Principal AI Agent Architecture & Development
Overview
A 30-year architect treats AI agents as distributed systems: they have state, dependencies, failure modes, and scaling limits. Building production-grade agents requires understanding token economics, context windows, tool integration patterns, and graceful degradation.
Agent Architecture Patterns
Pattern 1: Linear Chain (Deterministic)
Use case: Form filling, sequential data extraction, predictable workflows.
from langchain.llms import ChatOpenAI
from langchain.chains import SequentialChain
llm = ChatOpenAI(model='gpt-4', temperature=0)
# Step 1: Extract entities
entity_chain = LLMChain(
llm=llm,
prompt=PromptTemplate(
input_variables=['text'],
template="Extract all people names from: {text}"
),
output_key='entities'
)
# Step 2: Classify sentiment
sentiment_chain = LLMChain(
llm=llm,
prompt=PromptTemplate(
input_variables=['text'],
template="Rate sentiment of: {text} as positive/negative/neutral"
),
output_key='sentiment'
)
# Sequential execution
chain = SequentialChain(
chains=[entity_chain, sentiment_chain],
input_variables=['text'],
output_variables=['entities', 'sentiment']
)
result = chain({'text': "Alice and Bob are great friends!"})
# Output: {'entities': 'Alice, Bob', 'sentiment': 'positive'}
Advantage: Predictable, easy to debug, cheap token usage. Disadvantage: No adaptive behavior, no tool use, rigid structure.
Pattern 2: ReAct (Reasoning + Acting)
Use case: Research, API integration, multi-step problem solving.
from langchain.agents import initialize_agent, Tool
from langchain.agents import AgentType
# Define tools
tools = [
Tool(
name='web_search',
func=search_wikipedia,
description='Search Wikipedia for information'
),
Tool(
name='calculator',
func=eval_math,
description='Evaluate math expressions'
),
Tool(
name='web_scraper',
func=scrape_url,
description='Fetch and parse URL content'
)
]
# Create ReAct agent
agent = initialize_agent(
tools,
llm,
agent=AgentType.REACT_DOCSTRING, # Reasoning + Acting loop
verbose=True,
max_iterations=15,
early_stopping_method='generate'
)
# Execution
result = agent.run("What is the population of France? Multiply by 2 and verify.")
# Behind the scenes:
# 1. LLM reasons: "I need to search for France's population"
# 2. LLM calls: web_search('France population')
# 3. Tool returns: "France population is 67 million"
# 4. LLM reasons: "Now multiply by 2"
# 5. LLM calls: calculator('67000000 * 2')
# 6. Tool returns: "134000000"
# 7. LLM outputs: "The answer is 134 million"
Advantage: Adaptive, uses tools dynamically, handles emergent problems. Disadvantage: Unpredictable token usage, hallucination risks, latency.
Pattern 3: Planning + Execution
Use case: Large projects, multi-stage orchestration, resource constraints.
from langchain.agents import initialize_agent
from langchain.chains import LLMChain
from langchain.prompts import PromptTemplate
# Step 1: Planning (once, before execution)
planner = LLMChain(
llm=llm,
prompt=PromptTemplate(
input_variables=['objective'],
template="""Create a 5-step plan to achieve: {objective}
Format:
1. [Step 1]
2. [Step 2]
... etc
"""
)
)
# Step 2: Execution (follow the plan)
executor = initialize_agent(
tools,
llm,
agent=AgentType.OPENAI_FUNCTIONS,
verbose=True,
max_iterations=15
)
objective = "Build a customer support chatbot for a SaaS product"
plan = planner.run(objective)
# Output:
# 1. Define chatbot scope and use cases
# 2. Gather customer support tickets
# 3. Extract Q&A pairs from tickets
# 4. Train embeddings on Q&A pairs
# 5. Deploy chatbot with RAG pipeline
# Execute each step
result = executor.run(f"Execute this plan: {plan}")
Advantage: Cost-efficient (plan once, execute multiple times), transparent (explicit steps). Disadvantage: Less adaptive, requires manual plan intervention.
LangGraph (Agentic Control Flow)
LangGraph is a state machine framework for agents. Unlike LangChain chains, LangGraph handles conditional branching, loops, and persistence.
from langgraph.graph import StateGraph, START, END
from langgraph.checkpoint.memory import MemorySaver
from typing import TypedDict, Annotated
# Define agent state
class AgentState(TypedDict):
messages: Annotated[list, 'Append-only message history']
user_id: str
session_id: str
context: dict
# Node functions (each can make LLM calls, tool calls, etc.)
def query_node(state: AgentState) -> AgentState:
"""Process user query."""
response = llm.invoke(state['messages'])
state['messages'].append({'role': 'assistant', 'content': response})
return state
def tool_node(state: AgentState) -> AgentState:
"""Execute tool calls from LLM response."""
last_message = state['messages'][-1]
# Parse tool_calls from last_message
for tool_call in last_message['tool_calls']:
result = execute_tool(tool_call['name'], tool_call['args'])
state['messages'].append({'role': 'tool', 'content': result})
return state
def decision_node(state: AgentState) -> str:
"""Decide: continue or finish?"""
last_message = state['messages'][-1]
if 'tool_calls' in last_message:
return 'tool' # Go to tool_node
else:
return END # Done
# Build graph
workflow = StateGraph(AgentState)
workflow.add_node('query', query_node)
workflow.add_node('tool', tool_node)
workflow.add_edge(START, 'query')
workflow.add_conditional_edges('query', decision_node)
workflow.add_edge('tool', 'query') # Loop back to query after tool execution
# Compile with persistence
checkpointer = MemorySaver()
app = workflow.compile(checkpointer=checkpointer)
# Execute
state = {
'messages': [{'role': 'user', 'content': 'What is the weather?'}],
'user_id': 'user123',
'session_id': 'sess123',
'context': {}
}
result = app.invoke(state, config={'configurable': {'thread_id': 'sess123'}})
Key Features:
- Checkpointing: Resume interrupted conversations (human-in-the-loop).
- Conditional routing: Branches based on agent state.
- Memory persistence: Thread-based conversation history.
RAG (Retrieval-Augmented Generation) Pipelines
RAG is the pattern for grounding LLM responses in external knowledge. Prevents hallucination by retrieving relevant documents before generation.
RAG Architecture
User Query
↓
1. Embedding (Text → Vector)
↓
2. Retrieve (Vector Similarity Search)
↓
3. Rerank (Score Relevance)
↓
4. Augment (Inject into Prompt)
↓
5. Generate (LLM Produces Response)
Step 1: Data Ingestion & Chunking
from langchain.text_splitter import RecursiveCharacterTextSplitter
from langchain.document_loaders import PyPDFLoader, DirectoryLoader
# Load documents
loader = DirectoryLoader('./docs', glob='*.pdf', loader_cls=PyPDFLoader)
documents = loader.load()
# Chunking strategy (critical for RAG quality)
splitter = RecursiveCharacterTextSplitter(
chunk_size=1000, # Characters per chunk
chunk_overlap=200, # Overlap for context continuity
separators=['\n\n', '\n', '.', ' '] # Split on paragraphs first, then sentences
)
chunks = splitter.split_documents(documents)
# Chunks: List[Document]
# Each chunk has:
# - page_content: "The quick brown fox..."
# - metadata: {'source': 'doc.pdf', 'page': 5}
Chunking Strategy Considerations:
- Chunk Size: 500-2000 chars typical. Larger = more context, fewer chunks. Smaller = more precise, more chunks.
- Overlap: 200-500 chars prevents information split across chunks.
- Separators: Hierarchical (paragraphs → sentences → words) preserves semantic boundaries.
Step 2: Embedding & Vector Storage
from langchain.embeddings import OpenAIEmbeddings
from langchain.vectorstores import Pinecone
import pinecone
# Initialize embedding model
embeddings = OpenAIEmbeddings(model='text-embedding-3-large')
# Vector DB: Pinecone
pinecone.init(api_key=os.environ['PINECONE_API_KEY'])
index = pinecone.Index('documents')
# Store embeddings
vector_store = Pinecone.from_documents(
chunks,
embeddings,
index_name='documents'
)
# OR PostgreSQL with pgvector
from langchain.vectorstores.pgvector import PGVector
connection_string = 'postgresql://user:pass@localhost/vectordb'
vector_store = PGVector.from_documents(
chunks,
embeddings,
connection_string=connection_string,
table_name='documents'
)
Step 3: Retrieval & Reranking
from langchain.retrievers import ContextualCompressionRetriever
from langchain.retrievers.document_compressors import CohereReranker
from langchain.retrievers.multi_query import MultiQueryRetriever
# Simple retrieval (top-k by cosine similarity)
retriever = vector_store.as_retriever(
search_type='similarity',
search_kwargs={'k': 5} # Return top 5 chunks
)
# Reranking (re-score retrieved docs for relevance)
compressor = CohereReranker(model='rerank-english-v2.0', top_n=3)
compressed_retriever = ContextualCompressionRetriever(
base_compressor=compressor,
base_retriever=retriever
)
# Multi-query retrieval (query diversification)
multi_query = MultiQueryRetriever.from_llm(
retriever=retriever,
llm=llm,
prompt=MULTI_QUERY_PROMPT
)
# Execution
query = "How do I handle authentication in microservices?"
docs = compressed_retriever.get_relevant_documents(query)
# Returns: [Document(page_content='...'), Document(page_content='...'), ...]
Step 4: Augmented Generation
from langchain.chains import RetrievalQA
from langchain.prompts import PromptTemplate
# RAG prompt template
template = """Use the following context to answer the question.
Context:
{context}
Question: {question}
Answer:"""
prompt = PromptTemplate(
input_variables=['context', 'question'],
template=template
)
# RAG chain
rag_chain = RetrievalQA.from_chain_type(
llm=llm,
chain_type='stuff', # Other: 'map_reduce', 'refine'
retriever=compressed_retriever,
chain_type_kwargs={'prompt': prompt},
return_source_documents=True
)
# Execute
result = rag_chain({'query': 'How do I handle authentication in microservices?'})
# Output:
# {
# 'result': 'Use JWT tokens with refresh rotation...',
# 'source_documents': [Document(...), Document(...)]
# }
Context Window Management
LLM context windows are finite. Every token costs money and latency.
Token Counting & Optimization
from tiktoken import encoding_for_model
def estimate_tokens(text, model='gpt-4'):
"""Count tokens in text."""
encoding = encoding_for_model(model)
return len(encoding.encode(text))
# Optimization strategies
class ContextManager:
def __init__(self, max_tokens=8000):
self.max_tokens = max_tokens
self.token_count = 0
def add_message(self, role: str, content: str) -> bool:
"""Add message if it fits in context window."""
tokens = estimate_tokens(content)
if self.token_count + tokens > self.max_tokens:
# Evict oldest message
self.evict_oldest()
self.token_count += tokens
return True
def evict_oldest(self):
"""Remove oldest message to make room."""
oldest = self.messages.pop(0)
self.token_count -= estimate_tokens(oldest['content'])
# Usage
manager = ContextManager(max_tokens=8000)
manager.add_message('user', 'long query here')
manager.add_message('assistant', 'long response here')
Prompt Engineering (Advanced Patterns)
Chain-of-Thought (CoT)
Principle: Ask LLM to explain reasoning before answering.
Prompt:
"Let's think step by step. If Sally has 5 apples and gives 2 to Bob, how many does she have left?"
vs.
Standard prompt:
"Sally has 5 apples, gives 2 to Bob. How many left?"
Result: CoT improves accuracy on complex reasoning by 15-30%.
Few-Shot Learning
Principle: Provide examples before the actual query.
from langchain.prompts import FewShotPromptTemplate, PromptTemplate
examples = [
{'input': 'The food was delicious and the staff was friendly', 'output': 'Positive'},
{'input': 'The service was slow and the food was cold', 'output': 'Negative'},
{'input': 'The ambiance was nice, but pricey', 'output': 'Mixed'}
]
example_template = PromptTemplate(
input_variables=['input', 'output'],
template="Input: {input}\nOutput: {output}"
)
few_shot_prompt = FewShotPromptTemplate(
examples=examples,
example_prompt=example_template,
suffix="Input: {input}\nOutput:",
input_variables=['input']
)
# Output prompt includes all examples + new input
Structured Output (JSON Schema)
Principle: Force LLM to output structured JSON.
from langchain.output_parsers import PydanticOutputParser
from pydantic import BaseModel
class Person(BaseModel):
name: str
age: int
email: str
parser = PydanticOutputParser(pydantic_object=Person)
prompt_template = PromptTemplate(
template="Extract person info from: {text}\n{format_instructions}",
input_variables=['text'],
partial_variables={'format_instructions': parser.get_format_instructions()}
)
# LLM response is automatically parsed into Person object
Guardrails & Safety
Input Validation
from langchain.chains import GuardrailsChain
from langchain.prompts import PromptTemplate
class InputGuardrail:
def __init__(self):
self.blocked_keywords = ['execute', 'rm -rf', 'drop database']
def check(self, user_input: str) -> bool:
"""Return False if input contains dangerous keywords."""
for keyword in self.blocked_keywords:
if keyword.lower() in user_input.lower():
return False
return True
# Usage
guardrail = InputGuardrail()
if not guardrail.check(user_input):
raise ValueError("Input contains blocked content")
Output Validation
def validate_output(llm_output: str, constraints: dict) -> bool:
"""
Validate LLM output against constraints.
constraints = {
'max_length': 200,
'contains_citation': True,
'no_profanity': True
}
"""
if len(llm_output) > constraints.get('max_length', float('inf')):
return False
if constraints.get('contains_citation') and '[' not in llm_output:
return False
return True
Cost Optimization
class CostOptimizer:
# Token costs (2025 pricing)
MODELS = {
'gpt-4-turbo': {'input': 0.01, 'output': 0.03},
'gpt-4': {'input': 0.03, 'output': 0.06},
'gpt-3.5-turbo': {'input': 0.0005, 'output': 0.0015},
'claude-3-opus': {'input': 0.015, 'output': 0.075},
'claude-3-sonnet': {'input': 0.003, 'output': 0.015}
}
def estimate_cost(self, model: str, input_tokens: int, output_tokens: int) -> float:
rates = self.MODELS[model]
return (input_tokens * rates['input'] + output_tokens * rates['output']) / 1000
def select_model(self, task: str, budget: float) -> str:
"""Select cheapest model that meets requirements."""
if task == 'simple_classification':
return 'gpt-3.5-turbo' # Cheap, sufficient
elif task == 'complex_reasoning':
return 'gpt-4' # Expensive but necessary
elif task == 'long_context_rag':
return 'claude-3-opus' # Longest context window
return 'gpt-4-turbo' # Default balanced choice
Output Format
# 🤖 AI Agent Architecture Review
## I. Agent Pattern Assessment
- **Current Pattern**: [Linear / ReAct / Planning+Execution]
- **Recommendation**: [Pattern recommendation with rationale]
## II. RAG Pipeline Evaluation
- Chunking: Size [X] chars, Overlap [Y] chars
- Embedding Model: [OpenAI / Cohere / Local]
- Vector DB: [Pinecone / Weaviate / pgvector]
- Retrieval: [Cosine similarity / Hybrid search]
- Reranking: [Enabled / Disabled] - Recommend: [Enabled for production]
### RAG Quality Metrics
- Retrieval Precision@5: [X%]
- Answer Relevance: [Y%]
- Token Efficiency: [Z tokens/query]
## III. Context Management
- Max Context Window: [tokens]
- Average Query Token Count: [tokens]
- Headroom: [% of context window available]
## IV. Prompt Engineering Assessment
- [ ] Chain-of-Thought enabled for complex reasoning
- [ ] Few-shot examples provided (if needed)
- [ ] Structured output validation enabled
- [ ] Temperature tuned ([X] - 0=deterministic, 1=creative)
## V. Safety & Guardrails
- Input validation: [Implemented / Missing]
- Output validation: [Implemented / Missing]
- Rate limiting: [Implemented / Missing]
- Token limit enforcement: [Implemented / Missing]
## VI. Cost Analysis
- Est. Monthly Cost: $[X] at current usage
- Recommended Model: [Model] (balance quality/cost)
- Optimization Opportunities: [List any]
## VII. Skill Chaining
- Chain to `saas-architecture` for deployment patterns.
- Chain to `ml-pipeline` for training data pipelines.
Source: AniruddhaPKawarase/ai-agent-skills-toolkit — distributed by TomeVault.
先判断是否适合
作者设计意图
作者的方法与取舍
边界和复核