https://linen.dev logo
Calendly Python Script not executing the right too...
# 🖥│support-forum
s
I am testing out the calendly tool calling with Composio and using the code block listed in the doc : https://docs.composio.dev/toolkits/calendly. The user authentication works fine, but when i execute this code block it does not seem to call the right tool. I tried testing the same in the Composio playground by adding the tool "CALENDLY_LIST_USER_AVAILABILITY_SCHEDULES" and it gave back the correct response to my prompt of "What does my schedule look like for Wednesday?" Any help here is appreciated
c
Hey! Can you share the reproducible code snippet?
s
from composio import Composio from openai import OpenAI import json openai = OpenAI(api_key=OPENAI_API_KEY) calendly_auth_config_id = CALENDLY_AUTH_CONFIG_ID # Auth config ID created above user_id = USER_ID # UUID from database/application composio = Composio(api_key=COMPOSIO_API_KEY) tools = composio.tools.get(user_id=user_id, toolkits=["CALENDLY"]) print("[!] Tools:") print(json.dumps(tools)) def invoke_llm(task = "Am i free on Wednesday evening ?"): completion = openai.chat.completions.create( model="gpt-4o", messages=[ { "role": "user", "content": "Can you book a 30 mins meeting on wednesday evening?", # Your task here! }, ], tools=tools, ) # Handle Result from tool call result = composio.provider.handle_tool_calls(user_id=user_id, response=completion) print(f"[!] Completion: {completion}") print(f"[!] Tool call result: {result}") invoke_llm()
I noticed that print(Tools) does not print all the tools listed on the documentation.
u
Hi @surabhiprahalad, by default we return 20 Tools. You can use the param
limit
and set it to a higher number
composio.tools.get(user_id=user_id, toolkits=["CALENDLY"], limit=100)
. — Just to confirm, your prompt is different in your code snippet. Could you specify the expected Tool call and the prompt?
a
hey @surabhiprahalad, are you available for a quick call?
we limit to 20 tools by default since more tools can reduce accuracy in tool selection. You can increase the limit or specify particular tools if needed. I've updated your code to use the
CALENDLY_LIST_USER_AVAILABILITY_SCHEDULES
tool.
Copy code
from composio import Composio
from openai import OpenAI
import json

openai = OpenAI(api_key=OPENAI_API_KEY)
calendly_auth_config_id = CALENDLY_AUTH_CONFIG_ID # Auth config ID created above
user_id = USER_ID # UUID from database/application
composio = Composio(api_key=COMPOSIO_API_KEY)


#tools = composio.tools.get(user_id=user_id, toolkits=["CALENDLY"])

#increasing the limit
#tools = composio.tools.get(user_id=user_id, toolkits=["CALENDLY"], limit=30)

#getting specific tools
tools = composio.tools.get(user_id=user_id, tools=["CALENDLY_LIST_USER_AVAILABILITY_SCHEDULES"])

print("[!] Tools:")
print(json.dumps(tools))

def invoke_llm(task = "Am i free on Wednesday evening ?"):
    completion = openai.chat.completions.create(
        model="gpt-4o",
        messages=[
            {
                "role": "user",
                "content": "Can you book a 30 mins meeting on wednesday evening?",  # Your task here!
            },
        ],
        tools=tools,
    )

    # Handle Result from tool call
    result = composio.provider.handle_tool_calls(user_id=user_id, response=completion)
    print(f"[!] Completion: {completion}")
    print(f"[!] Tool call result: {result}")

invoke_llm()
Let me know if you need help. https://calendly.com/abhishek-composio/30min
s
i can chat for 15 mins now ?
a
To join the video meeting, click this link: https://meet.google.com/hvo-jabk-wvt Otherwise, to join by phone, dial +1 470-443-0073 and enter this PIN: 936 588 352# To view more phone numbers, click this link: https://tel.meet/hvo-jabk-wvt?hs=5
Hey @surabhiprahalad, Can you try this?
Copy code
from composio import Composio
from composio_openai_agents import OpenAIAgentsProvider
from openai import OpenAI
import asyncio
from agents import Agent, Runner

openai = OpenAI()
composio = Composio(api_key="<composio_api_key>", provider=OpenAIAgentsProvider())

tools = composio.tools.get(user_id="abhishek", tools=["CALENDLY_GET_USER","CALENDLY_LIST_USER_AVAILABILITY_SCHEDULES"])

agent = Agent(
    name="Calendly Agent",
    instructions="You're an AI agent that can check the calendly availability for the user and book a meeting if available.",
    tools=tools,
)

async def main():
    result = await Runner.run(
        starting_agent=agent,
        input=(
            "Check my calendly availability for wednesday evening"
        ),
    )
    print(result.final_output)
asyncio.run(main())
Here's the doc: https://docs.composio.dev/providers/openai-agents You can use Composio's search tools to get the relevant tools based on usecase: https://docs.composio.dev/toolkits/composio#composio_search_tools
s
I think the Async main run is causing issues coz there is already a running loop . do you see the same issue ?
k
Hi @surabhiprahalad, it did work for me: ➜ try git:(next) ✗ python try.py You are available for meetings on Wednesday evening. According to your default working hours (America/Los_Angeles time), your availability on Wednesdays is from 11:00 AM to 11:45 PM. So, any time on Wednesday evening is open for booking! If you’d like me to book a meeting for a specific time on Wednesday evening, please provide the desired time slot.
Happy to jump on a quick call if that helps. Also, happy to setup a slack channel if that's faster. Also, we are launching a much simpler interface to just use https://rube.app/ in the application.