|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "raw", |
| 5 | + "id": "10238e62-3465-4973-9279-606cbb7ccf16", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "---\n", |
| 9 | + "sidebar_label: Stripe\n", |
| 10 | + "---" |
| 11 | + ] |
| 12 | + }, |
| 13 | + { |
| 14 | + "cell_type": "markdown", |
| 15 | + "id": "a6f91f20", |
| 16 | + "metadata": {}, |
| 17 | + "source": [ |
| 18 | + "# StripeAgentToolkit\n", |
| 19 | + "\n", |
| 20 | + "This notebook provides a quick overview for getting started with Stripe's agent toolkit.\n", |
| 21 | + "\n", |
| 22 | + "You can read more about `StripeAgentToolkit` in [Stripe's launch blog](https://stripe.dev/blog/adding-payments-to-your-agentic-workflows) or on the project's [PyPi page](https://pypi.org/project/stripe-agent-toolkit/).\n", |
| 23 | + "\n", |
| 24 | + "## Overview\n", |
| 25 | + "\n", |
| 26 | + "### Integration details\n", |
| 27 | + "\n", |
| 28 | + "| Class | Package | Serializable | [JS Support](https://github.com/stripe/agent-toolkit?tab=readme-ov-file#typescript) | Package latest |\n", |
| 29 | + "| :--- | :--- | :---: | :---: | :---: |\n", |
| 30 | + "| StripeAgentToolkit | [stripe-agent-toolkit](https://pypi.org/project/stripe-agent-toolkit) | ❌ | ✅ |  |\n", |
| 31 | + "\n", |
| 32 | + "\n", |
| 33 | + "## Setup\n", |
| 34 | + "\n", |
| 35 | + "This externally-managed package is hosted out of the `stripe-agent-toolkit` project, which is managed by Stripe's team.\n", |
| 36 | + "\n", |
| 37 | + "You can install it, along with langgraph for the following examples, with `pip`:" |
| 38 | + ] |
| 39 | + }, |
| 40 | + { |
| 41 | + "cell_type": "code", |
| 42 | + "execution_count": 1, |
| 43 | + "id": "f85b4089", |
| 44 | + "metadata": {}, |
| 45 | + "outputs": [ |
| 46 | + { |
| 47 | + "name": "stdout", |
| 48 | + "output_type": "stream", |
| 49 | + "text": [ |
| 50 | + "\n", |
| 51 | + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n", |
| 52 | + "\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n", |
| 53 | + "Note: you may need to restart the kernel to use updated packages.\n" |
| 54 | + ] |
| 55 | + } |
| 56 | + ], |
| 57 | + "source": [ |
| 58 | + "%pip install --quiet -U langgraph stripe-agent-toolkit" |
| 59 | + ] |
| 60 | + }, |
| 61 | + { |
| 62 | + "cell_type": "markdown", |
| 63 | + "id": "b15e9266", |
| 64 | + "metadata": {}, |
| 65 | + "source": [ |
| 66 | + "### Credentials\n", |
| 67 | + "\n", |
| 68 | + "In addition to installing the package, you will need to configure the integration with your Stripe account's secret key, which is available in your [Stripe Dashboard](https://dashboard.stripe.com/account/apikeys)." |
| 69 | + ] |
| 70 | + }, |
| 71 | + { |
| 72 | + "cell_type": "code", |
| 73 | + "execution_count": null, |
| 74 | + "id": "e0b178a2-8816-40ca-b57c-ccdd86dde9c9", |
| 75 | + "metadata": {}, |
| 76 | + "outputs": [], |
| 77 | + "source": [ |
| 78 | + "import getpass\n", |
| 79 | + "import os\n", |
| 80 | + "\n", |
| 81 | + "if not os.environ.get(\"STRIPE_SECRET_KEY\"):\n", |
| 82 | + " os.environ[\"STRIPE_SECRET_KEY\"] = getpass.getpass(\"STRIPE API key:\\n\")" |
| 83 | + ] |
| 84 | + }, |
| 85 | + { |
| 86 | + "cell_type": "markdown", |
| 87 | + "id": "bc5ab717-fd27-4c59-b912-bdd099541478", |
| 88 | + "metadata": {}, |
| 89 | + "source": [ |
| 90 | + "It's also helpful (but not needed) to set up [LangSmith](https://smith.langchain.com/) for best-in-class observability:" |
| 91 | + ] |
| 92 | + }, |
| 93 | + { |
| 94 | + "cell_type": "code", |
| 95 | + "execution_count": 3, |
| 96 | + "id": "a6c2f136-6367-4f1f-825d-ae741e1bf281", |
| 97 | + "metadata": {}, |
| 98 | + "outputs": [], |
| 99 | + "source": [ |
| 100 | + "# os.environ[\"LANGCHAIN_TRACING_V2\"] = \"true\"\n", |
| 101 | + "# os.environ[\"LANGCHAIN_API_KEY\"] = getpass.getpass()" |
| 102 | + ] |
| 103 | + }, |
| 104 | + { |
| 105 | + "cell_type": "markdown", |
| 106 | + "id": "1c97218f-f366-479d-8bf7-fe9f2f6df73f", |
| 107 | + "metadata": {}, |
| 108 | + "source": [ |
| 109 | + "## Instantiation\n", |
| 110 | + "\n", |
| 111 | + "Here we show how to create an instance of the Stripe Toolkit" |
| 112 | + ] |
| 113 | + }, |
| 114 | + { |
| 115 | + "cell_type": "code", |
| 116 | + "execution_count": null, |
| 117 | + "id": "8b3ddfe9-ca79-494c-a7ab-1f56d9407a64", |
| 118 | + "metadata": {}, |
| 119 | + "outputs": [], |
| 120 | + "source": [ |
| 121 | + "from stripe_agent_toolkit.crewai.toolkit import StripeAgentToolkit\n", |
| 122 | + "\n", |
| 123 | + "stripe_agent_toolkit = StripeAgentToolkit(\n", |
| 124 | + " secret_key=os.getenv(\"STRIPE_SECRET_KEY\"),\n", |
| 125 | + " configuration={\n", |
| 126 | + " \"actions\": {\n", |
| 127 | + " \"payment_links\": {\n", |
| 128 | + " \"create\": True,\n", |
| 129 | + " },\n", |
| 130 | + " }\n", |
| 131 | + " },\n", |
| 132 | + ")" |
| 133 | + ] |
| 134 | + }, |
| 135 | + { |
| 136 | + "cell_type": "markdown", |
| 137 | + "id": "4f53188e", |
| 138 | + "metadata": {}, |
| 139 | + "source": [ |
| 140 | + "## Agent\n", |
| 141 | + "\n", |
| 142 | + "Here's how to use the toolkit to create a basic agent in langgraph:" |
| 143 | + ] |
| 144 | + }, |
| 145 | + { |
| 146 | + "cell_type": "code", |
| 147 | + "execution_count": null, |
| 148 | + "id": "4975924e", |
| 149 | + "metadata": {}, |
| 150 | + "outputs": [], |
| 151 | + "source": [ |
| 152 | + "from langchain_anthropic import ChatAnthropic\n", |
| 153 | + "from langgraph.prebuilt import create_react_agent\n", |
| 154 | + "\n", |
| 155 | + "llm = ChatAnthropic(\n", |
| 156 | + " model=\"claude-3-5-sonnet-20240620\",\n", |
| 157 | + ")\n", |
| 158 | + "\n", |
| 159 | + "langgraph_agent_executor = create_react_agent(llm, stripe_agent_toolkit.get_tools())\n", |
| 160 | + "\n", |
| 161 | + "input_state = {\n", |
| 162 | + " \"messages\": \"\"\"\n", |
| 163 | + " Create a payment link for a new product called 'test' with a price\n", |
| 164 | + " of $100. Come up with a funny description about buy bots,\n", |
| 165 | + " maybe a haiku.\n", |
| 166 | + " \"\"\",\n", |
| 167 | + "}\n", |
| 168 | + "\n", |
| 169 | + "output_state = langgraph_agent_executor.invoke(input_state)\n", |
| 170 | + "\n", |
| 171 | + "print(output_state[\"messages\"][-1].content)" |
| 172 | + ] |
| 173 | + } |
| 174 | + ], |
| 175 | + "metadata": { |
| 176 | + "kernelspec": { |
| 177 | + "display_name": ".venv", |
| 178 | + "language": "python", |
| 179 | + "name": "python3" |
| 180 | + }, |
| 181 | + "language_info": { |
| 182 | + "codemirror_mode": { |
| 183 | + "name": "ipython", |
| 184 | + "version": 3 |
| 185 | + }, |
| 186 | + "file_extension": ".py", |
| 187 | + "mimetype": "text/x-python", |
| 188 | + "name": "python", |
| 189 | + "nbconvert_exporter": "python", |
| 190 | + "pygments_lexer": "ipython3", |
| 191 | + "version": "3.11.4" |
| 192 | + } |
| 193 | + }, |
| 194 | + "nbformat": 4, |
| 195 | + "nbformat_minor": 5 |
| 196 | +} |
0 commit comments