Skip to main content
Open In Colab在 GitHub 上打开

StripeAgentToolkit

此笔记本提供了 Stripe 代理工具包入门的快速概述。

您可以阅读更多关于StripeAgentToolkitStripe 的发布博客或项目的 PyPi 页面上

概述

集成详细信息

序列 化JS 支持最新包装
StripeAgentToolkitstripe-agent-toolkitPyPI - Version

设置

此外部管理的包托管在stripe-agent-toolkit项目,该项目由 Stripe 的团队管理。

您可以将其与以下示例的 langgraph 一起安装,使用pip:

%pip install --quiet -U langgraph stripe-agent-toolkit

[notice] A new release of pip is available: 24.2 -> 24.3.1
[notice] To update, run: pip install --upgrade pip
Note: you may need to restart the kernel to use updated packages.

凭据

除了安装软件包之外,您还需要配置与 Stripe 账户密钥的集成,该密钥可在 Stripe 管理平台中找到。

import getpass
import os

if not os.environ.get("STRIPE_SECRET_KEY"):
os.environ["STRIPE_SECRET_KEY"] = getpass.getpass("STRIPE API key:\n")

设置 LangSmith 以实现一流的可观测性也很有帮助(但不是必需的):

# os.environ["LANGSMITH_TRACING"] = "true"
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass()

实例

在这里,我们将展示如何创建 Stripe Toolkit 的实例

from stripe_agent_toolkit.crewai.toolkit import StripeAgentToolkit

stripe_agent_toolkit = StripeAgentToolkit(
secret_key=os.getenv("STRIPE_SECRET_KEY"),
configuration={
"actions": {
"payment_links": {
"create": True,
},
}
},
)

代理

以下是使用工具包在 langgraph 中创建基本代理的方法:

from langchain_anthropic import ChatAnthropic
from langgraph.prebuilt import create_react_agent

llm = ChatAnthropic(
model="claude-3-5-sonnet-20240620",
)

langgraph_agent_executor = create_react_agent(llm, stripe_agent_toolkit.get_tools())

input_state = {
"messages": """
Create a payment link for a new product called 'test' with a price
of $100. Come up with a funny description about buy bots,
maybe a haiku.
""",
}

output_state = langgraph_agent_executor.invoke(input_state)

print(output_state["messages"][-1].content)