Skip to content

strands support in python toolkit #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/examples/strands/.env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
OPENAI_API_KEY=""
STRIPE_SECRET_KEY=""
15 changes: 15 additions & 0 deletions python/examples/strands/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from strands import Agent
from strands_tools import calculator, file_read, shell

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

git+https://github.com//.git@<commit_or_tag>#egg=strands-agent

# Add tools to our agent
agent = Agent(
tools=[calculator, file_read, shell]
)

# Agent will automatically determine when to use the calculator tool
agent("What is 42 ^ 9")

print("\n\n") # Print new lines

# Agent will use the shell and file reader tool when appropriate
agent("Show me the contents of a single file in this directory")
2 changes: 2 additions & 0 deletions python/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ ruff==0.4.4
stripe==11.0.0
openai==1.66.0
openai-agents==0.0.2
strands-agent>=0.1.0
strands-agents-tools
18 changes: 18 additions & 0 deletions python/stripe_agent_toolkit/strands/tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from strands.tools.tools import PythonAgentTool as StrandTool
import json

def StripeTool(api, tool) -> StrandTool:
parameters = tool["args_schema"].model_json_schema()
parameters["additionalProperties"] = False
parameters["type"] = "object"
return StrandTool(
tool_name=tool["method"],
tool_spec={
"name": tool["method"],
"description": tool["description"],
"inputSchema": {
"json": parameters
}
},
callback=lambda x: api.run(tool["method"], **json.loads(x))
)
43 changes: 43 additions & 0 deletions python/stripe_agent_toolkit/strands/toolkit.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Stripe Agent Toolkit."""

from typing import List, Optional
from pydantic import PrivateAttr
import json

from strands.tools.tools import PythonAgentTool as StrandTool


from ..api import StripeAPI
from ..tools import tools
from ..configuration import Configuration, is_tool_allowed
from .tool import StripeTool
from .hooks import BillingHooks

class StripeAgentToolkit:
_tools: List[FunctionTool] = PrivateAttr(default=[])
_stripe_api: StripeAPI = PrivateAttr(default=None)

def __init__(
self, secret_key: str, configuration: Optional[Configuration] = None
):
super().__init__()

context = configuration.get("context") if configuration else None

self._stripe_api = StripeAPI(secret_key=secret_key, context=context)

filtered_tools = [
tool for tool in tools if is_tool_allowed(tool, configuration)
]

self._tools = [
StripeTool(self._stripe_api, tool)
for tool in filtered_tools
]

def get_tools(self) -> List[FunctionTool]:
"""Get the tools in the toolkit."""
return self._tools

def billing_hook(self, type: Optional[str] = None, customer: Optional[str] = None, meter: Optional[str] = None, meters: Optional[dict[str, str]] = None) -> BillingHooks:
return BillingHooks(self._stripe_api, type, customer, meter, meters)
Loading