forked from ravilaudya/task-copilot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalendar_agent.py
62 lines (52 loc) · 2.34 KB
/
calendar_agent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
from multi_agent_orchestrator.agents import ChainAgent, ChainAgentOptions, AgentCallbacks
from multi_agent_orchestrator.agents import BedrockLLMAgent, BedrockLLMAgentOptions
from api_agent import ApiAgent, ApiAgentOptions
import asyncio
import chainlit as cl
import os
from dotenv import load_dotenv
from datetime import datetime
from datetime import timedelta
# Load environment variables from .env file
load_dotenv()
# Access environment variables
CALENDLY_AUTH_TOKEN = os.getenv('CALENDLY_AUTH_TOKEN')
CALENDLY_USER_URI = os.getenv('CALENDLY_USER_URI')
if not CALENDLY_AUTH_TOKEN:
raise ValueError("CALENDLY_AUTH_TOKEN environment variable not set")
if not CALENDLY_USER_URI:
raise ValueError("CALENDLY_USER_URI environment variable not set")
class ChainlitAgentCallbacks(AgentCallbacks):
def on_llm_new_token(self, token: str) -> None:
asyncio.run(cl.user_session.get("current_msg").stream_token(token))
def custom_headers_callback():
return {
'Authorization': f'Bearer {CALENDLY_AUTH_TOKEN}',
}
start_time = datetime.now().isoformat()
end_time = (datetime.now() + timedelta(days=10)).isoformat()
agent1 = ApiAgent(ApiAgentOptions(
endpoint = f"https://api.calendly.com/user_busy_times?user={CALENDLY_USER_URI}&start_time={start_time}&end_time={end_time}",
method = "GET",
name = "Calendly Schedule Agent",
description = "Specializes in Calendar scheduling",
streaming=False,
headers_callback=custom_headers_callback,
))
agent2 = BedrockLLMAgent(BedrockLLMAgentOptions(
name="Calendar Summarization",
streaming=True,
description="You are an AI agent specialized in summarizing calendar events. Given a list of events, produce a concise summary"\
" highlighting key details such as event names, dates, times, and participants. Ensure the summary is clear, brief, and "\
"informative for quick understanding. Do not provide duplicate information or irrelevant details.",
model_id="anthropic.claude-3-5-sonnet-20240620-v1:0",
callbacks=ChainlitAgentCallbacks()
))
options = ChainAgentOptions(
name='Calendar Reader and Summarization Agent',
description='You are an AI agent that reads calendar events from calendly and summarizes them.',
agents=[agent1, agent2],
default_output='Sorry, encountered an issue.',
save_chat=True
)
calendar_agent = ChainAgent(options)