connectors.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. """
  2. This example demonstrates how to use openai's connector feature
  3. with the agency swarm framework.
  4. Pre-requisites:
  5. - You need to have a Google Calendar account with some events in the last 6 months.
  6. - Google OAuth token.
  7. ## How to get Google OAuth token:
  8. - Go to https://developers.google.com/oauthplayground
  9. - Enter https://www.googleapis.com/auth/calendar.events in the "Input your own scopes" field
  10. - Click on the "Authorize APIs" button
  11. - In the step 2, click on the "Exchange authorization code for tokens" button
  12. - Copy access token and paste it in the "authorization" field in the example below
  13. Run the example with: python examples/connectors.py
  14. Agent will be able to get past events from your Google Calendar.
  15. """
  16. import datetime
  17. from agents import HostedMCPTool
  18. from agency_swarm import Agency, Agent
  19. current_date = datetime.datetime.now()
  20. calendar_assistant = Agent(
  21. name="CalendarAssistant",
  22. instructions=f"You are an assistant that can access user's Google Calendar. Current date is {current_date}.",
  23. tools=[
  24. HostedMCPTool(
  25. tool_config={
  26. "type": "mcp",
  27. "server_label": "google_calendar",
  28. "connector_id": "connector_googlecalendar",
  29. "authorization": "your-oauth-token",
  30. "require_approval": "never",
  31. },
  32. )
  33. ],
  34. )
  35. agency = Agency(calendar_assistant)
  36. if __name__ == "__main__":
  37. print(agency.get_response_sync("name 3 events from my Google Calendar that happened in the last 6 months"))