Stripe Agent Toolkit 使用教程
1. 项目介绍
Stripe Agent Toolkit 是一个开源库,用于帮助开发者将 Stripe API 集成到各种代理工作流程中。该库支持 Python 和 TypeScript 语言,构建在 Stripe 的 Python 和 Node SDK 之上。它允许流行的代理框架如 OpenAI 的 Agent SDK、LangChain、CrewAI、Vercel 的 AI SDK 和 Model Context Protocol (MCP) 通过函数调用与 Stripe API 进行集成。
2. 项目快速启动
Python 版本
安装:
pip install stripe-agent-toolkit
使用:
from stripe_agent_toolkit.openai.toolkit import StripeAgentToolkit
stripe_agent_toolkit = StripeAgentToolkit(
secret_key="sk_test_...",
configuration={
"actions": {
"payment_links": {
"create": True
}
}
}
)
TypeScript 版本
安装:
npm install @stripe/agent-toolkit
使用:
import { StripeAgentToolkit } from "@stripe/agent-toolkit/langchain";
const stripeAgentToolkit = new StripeAgentToolkit({
secretKey: process.env.STRIPE_SECRET_KEY!,
configuration: {
actions: {
paymentLinks: {
create: true
}
}
}
});
3. 应用案例和最佳实践
创建支付链接
在 Python 中:
# 假设 stripe_agent_toolkit 已经初始化
payment_link = stripe_agent_toolkit.create_payment_link()
在 TypeScript 中:
// 假设 stripeAgentToolkit 已经初始化
const paymentLink = await stripeAgentToolkit.createPaymentLink();
集成到代理框架
在 Python 中使用 OpenAI 的 Agent SDK:
from agents import Agent
stripe_agent = Agent(
name="Stripe Agent",
instructions="You are an expert at integrating with Stripe",
tools=stripe_agent_toolkit.get_tools()
)
在 TypeScript 中使用 LangChain:
import { AgentExecutor, createStructuredChatAgent } from "langchain/agents";
const tools = stripeAgentToolkit.getTools();
const agent = await createStructuredChatAgent({ llm, tools, prompt });
4. 典型生态项目
- OpenAI's Agent SDK:用于创建可以与用户进行交互的智能代理。
- LangChain:提供了一系列工具和库来帮助构建复杂的语言模型应用。
- CrewAI:一个机器学习平台,用于构建和部署智能系统。
- Vercel's AI SDK:为 Vercel 平台上的开发者提供了构建 AI 应用的工具。
以上就是 Stripe Agent Toolkit 的使用教程,希望对您的开发工作有所帮助。