Skip to content

Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

fix: python before-execute demo

angrybaybladee08ccd6c0ff5
diff --git a/fern/docs/tool-calling/before-execution-modifiers.mdx b/fern/docs/tool-calling/before-execution-modifiers.mdx
index dce86eeb5..56db2a2f5 100644
--- a/fern/docs/tool-calling/before-execution-modifiers.mdx
+++ b/fern/docs/tool-calling/before-execution-modifiers.mdx
@@ -70,9 +70,14 @@ if (tool_calls) {
```
```python Python maxLines=60 wordWrap
+from openai import OpenAI
from composio import Composio, before_execute
from composio.types import ToolExecuteParams
+composio = Composio()
+openai_client = OpenAI()
+user_id = "[email protected]"
+
@before_execute(tools=["HACKERNEWS_GET_LATEST_POSTS"])
def before_execute_modifier(
tool: str,
@@ -82,21 +87,25 @@ def before_execute_modifier(
params["arguments"]["size"] = 1
return params
+
+# Get tools
+tools = composio.tools.get(user_id=user_id, slug="HACKERNEWS_GET_LATEST_POSTS")
+
# Get response from the LLM
response = openai_client.chat.completions.create(
model="gpt-4o-mini",
tools=tools,
- messages=messages,
+ messages=[{"role": "user", "content": "Fetch latest posts from hackernews"}],
)
print(response)
# Execute the function calls.
result = composio.provider.handle_tool_calls(
- response=response,
- user_id="default",
- modifiers=[
- before_execute_modifier,
- ]
+ response=response,
+ user_id="default",
+ modifiers=[
+ before_execute_modifier,
+ ],
)
print(result)
```