# エージェントワークフローに Stripe を追加する エージェントで金融サービスを使用します。 Stripe を利用してエージェントビジネスを運営し、エージェントの機能を強化します。金融サービスとツールへのアクセスを提供すると、エージェントは資金の獲得と利用をサポートできるようになり、その機能を拡張できます。 ## Stripe オブジェクトを作成する 関数呼び出しを使用して Stripe オブジェクトを作成し、管理します。たとえば、資金を受け取るための [Payment Links](https://docs.stripe.com/payment-links.md) を動的に作成し、顧客をサポートするためのサポートワークフローに導入し、テストデータを作成します。 Stripe のエージェントツールキットは、[OpenAI の Agents SDK](https://github.com/openai/openai-agents-python)、[Vercel の AI SDK](https://sdk.vercel.ai/)、[LangChain](https://www.langchain.com/)、[CrewAI](https://www.crewai.com/) をサポートしています。関数呼び出しをサポートし、Python および TypeScript と互換性のある任意の LLM プロバイダーで動作します。 #### OpenAI Agents SDK #### Python ```python import asyncio import os from agents import Agent, Runner from stripe_agent_toolkit.openai.toolkit import create_stripe_agent_toolkit async def main(): # Initialize toolkit - use restricted key (rk_*) for better security toolkit = await create_stripe_agent_toolkit( secret_key=os.getenv("STRIPE_SECRET_KEY") ) try: agent = Agent( name="Stripe Agent", instructions="Integrate with Stripe effectively to support business needs.", tools=toolkit.get_tools() ) assignment = "Create a payment link for a new product called \"Test\" with a price of $100." result = await Runner.run(agent, assignment) print(result.final_output) finally: await toolkit.close() if __name__ == "__main__": asyncio.run(main()) ``` #### Vercel AI SDK #### Node.js ```javascript import { createStripeAgentToolkit } from '@stripe/agent-toolkit/ai-sdk'; import { openai } from '@ai-sdk/openai'; import { generateText } from 'ai'; // Initialize toolkit - use restricted key (rk_*) for better security const toolkit = await createStripeAgentToolkit({ secretKey: process.env.STRIPE_SECRET_KEY!, configuration: {}, }); try { const result = await generateText({ model: openai('gpt-4o'), tools: { ...toolkit.getTools(), }, maxSteps: 5, prompt: 'Create a payment link for a new product called \"Test\" with a price of $100.', }); } finally { await toolkit.close(); } ``` #### LangChain #### Python ```python import asyncio import os from langchain_openai import ChatOpenAI from langchain.agents import AgentExecutor, create_structured_chat_agent from langchain.prompts import ChatPromptTemplate from stripe_agent_toolkit.langchain.toolkit import create_stripe_agent_toolkit async def main(): # Initialize toolkit - use restricted key (rk_*) for better security toolkit = await create_stripe_agent_toolkit( secret_key=os.getenv("STRIPE_SECRET_KEY") ) try: llm = ChatOpenAI(model="gpt-4") prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant that can interact with Stripe."), ("human", "{input}"), ("placeholder", "{agent_scratchpad}"), ]) tools = toolkit.get_tools() agent = create_structured_chat_agent(llm, tools, prompt) agent_executor = AgentExecutor(agent=agent, tools=tools) agent_executor.invoke({ "input": "Create a payment link for a new product called \"Test\" with a price of $100." }) finally: await toolkit.close() if __name__ == "__main__": asyncio.run(main()) ``` #### CrewAI #### Python ```python import asyncio import os from crewai import Agent, Task, Crew from stripe_agent_toolkit.crewai.toolkit import create_stripe_agent_toolkit async def main(): # Initialize toolkit - use restricted key (rk_*) for better security toolkit = await create_stripe_agent_toolkit( secret_key=os.getenv("STRIPE_SECRET_KEY") ) try: stripe_agent = Agent( role="Stripe Agent", goal="Integrate with Stripe effectively to support business needs.", backstory="You are a Stripe expert.", tools=[*toolkit.get_tools()] ) create_payment_link = Task( description="Create a payment link for a new product called \"Test\" with a price of $100.", expected_output="url", agent=stripe_agent ) crew = Crew( agents=[stripe_agent], tasks=[create_payment_link], planning=True ) crew.kickoff() finally: await toolkit.close() if __name__ == "__main__": asyncio.run(main()) ``` > この SDK を使用して Stripe をエージェンティックワークフローに導入する方法をご紹介します。エージェントの動作は決定論的ではないため、[サンドボックス](https://docs.stripe.com/sandboxes.md) で SDK を使用し、評価を実行してアプリケーションのパフォーマンスを評価します。 > > セキュリティ上の理由から、特に本番環境では、[制限された API キー](https://docs.stripe.com/keys.md#create-restricted-api-secret-key) (`rk_*`) を使用して、エージェントのアクセスを必要な機能のみに制限することを強くお勧めします。ツールを使用できるかどうかは、制限されたキーに設定された権限によって決まります。