Skip to content

How can I insert an event in my calender using 365 toolkits ? #1085

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
aspirant2018 opened this issue Jun 7, 2024 · 5 comments
Open

How can I insert an event in my calender using 365 toolkits ? #1085

aspirant2018 opened this issue Jun 7, 2024 · 5 comments
Labels
needs triage Not yet classified, needs a closer look

Comments

@aspirant2018
Copy link

Hey guys,
I have created an agent using 365 toolkits to interact with my calender. the authentification and extracting events works fine. example:
Capture d’écran 2024-06-07 à 14 36 08

the result:
I found an upcoming event in your calendar for June 2024:

Subject: testing_event
Start Date and Time: June 7, 2024, at 12:00 PM UTC
End Date and Time: June 7, 2024, at 12:05 PM UTC

If you need more information or assistance with this event, feel free to let me know!
The problem occurs when I want to insert a new event that's when I got this error:

[/usr/local/lib/python3.10/dist-packages/O365/calendar.py](https://localhost:8080/#) in start(self, value)
1070 else:
1071 if not isinstance(value.tzinfo, ZoneInfo):
-> 1072 raise ValueError('TimeZone data must be set using ZoneInfo objects')
1073 self.__start = value
1074 if not self.end:

ValueError: TimeZone data must be set using ZoneInfo objects

@aspirant2018
Copy link
Author

and when I used it as aZoneInfo object:

from zoneinfo import ZoneInfo
from datetime import datetime

# Create a ZoneInfo object for a specific timezone, for example, 'America/New_York'
ny_timezone = ZoneInfo("UTC")

# Get the current time in the specified timezone
current_time = datetime.now(ny_timezone)

print("Current time in UTC:", current_time)

answer = agent_events.invoke(
    f"Can you make a 30 minute meeting with a sentient parrot to discuss research collaborations on {current_time}?"
)
print(answer['output'])

I got this output

> Entering new AgentExecutor chain...

Invoking: `events_search` with `{'start_datetime': '2024-06-07T13:00:00+00:00', 'end_datetime': '2024-06-07T14:00:00+00:00'}`


[]
Invoking: `send_event` with `{'body': 'Discuss research collaborations with a sentient parrot.', 'attendees': ['[[email protected]](mailto:[email protected])'], 'subject': 'Research Collaborations Meeting', 'start_datetime': '2024-06-07T13:21:17.628675+00:00', 'end_datetime': '2024-06-07T13:51:17.628675+00:00'}`


---------------------------------------------------------------------------

ValueError                                Traceback (most recent call last)

[<ipython-input-272-4eafbd13a3f4>](https://localhost:8080/#) in <cell line: 12>()
     10 print("Current time in UTC:", current_time)
     11 
---> 12 answer = agent_events.invoke(
     13     f"Can you make a 30 minute meeting with a sentient parrot to discuss research collaborations on {current_time}?"
     14 )

11 frames

[/usr/lib/python3.10/_strptime.py](https://localhost:8080/#) in _strptime(data_string, format)
    347     found = format_regex.match(data_string)
    348     if not found:
--> 349         raise ValueError("time data %r does not match format %r" %
    350                          (data_string, format))
    351     if len(data_string) != found.end():

ValueError: time data '2024-06-07T13:21:17.628675+00:00' does not match format '%Y-%m-%dT%H:%M:%S%z'

ValueError: time data '2024-06-07T13:21:17.628675+00:00' does not match format '%Y-%m-%dT%H:%M:%S%z

@alejcas
Copy link
Member

alejcas commented Jun 14, 2024

I don't see in your traceback what O365 call is giving this error.

If you just create the event using the same params by code... works?

@aspirant2018
Copy link
Author

Hello , thank you for replying to me .

so when i excute this code:


answer = agent_events.invoke(
    f"add an event at 2024-06-07 at 12:00:00 PM to recall John  ?"
)
print(answer['output'])

I got this error

/usr/local/lib/python3.10/dist-packages/ipykernel/ipkernel.py:283: DeprecationWarning: should_run_async will not call transform_cell automatically in the future. Please pass the result to transformed_cell argument and any exception that happen during thetransform in preprocessing_exc_tuple in IPython 7.17 and above.
def _forward_input(self, allow_stdin=False):

Entering new AgentExecutor chain...

Invoking: send_event with {'body': 'Reminder to recall John', 'attendees': ['John'], 'subject': 'Recall John', 'start_datetime': '2024-06-07T12:00:00+00:00', 'end_datetime': '2024-06-07T13:00:00+00:00'}


ValueError Traceback (most recent call last)

in <cell line: 1>()
----> 1 answer = agent_events.invoke(
2 f"add an event at 2024-06-07 at 12:00:00 PM to recall John ?"
3 )
4 print(answer['output'])

10 frames

/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py in invoke(self, input, config, **kwargs)
164 except BaseException as e:
165 run_manager.on_chain_error(e)
--> 166 raise e
167 run_manager.on_chain_end(outputs)
168

/usr/local/lib/python3.10/dist-packages/langchain/chains/base.py in invoke(self, input, config, **kwargs)
154 self._validate_inputs(inputs)
155 outputs = (
--> 156 self._call(inputs, run_manager=run_manager)
157 if new_arg_supported
158 else self._call(inputs)

/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py in _call(self, inputs, run_manager)
1431 # We now enter the agent loop (until it returns something).
1432 while self._should_continue(iterations, time_elapsed):
-> 1433 next_step_output = self._take_next_step(
1434 name_to_tool_map,
1435 color_mapping,

/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py in _take_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)
1137 ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:
1138 return self._consume_next_step(
-> 1139 [
1140 a
1141 for a in self._iter_next_step(

/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py in (.0)
1137 ) -> Union[AgentFinish, List[Tuple[AgentAction, str]]]:
1138 return self._consume_next_step(
-> 1139 [
1140 a
1141 for a in self._iter_next_step(

/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py in _iter_next_step(self, name_to_tool_map, color_mapping, inputs, intermediate_steps, run_manager)
1222 yield agent_action
1223 for agent_action in actions:
-> 1224 yield self._perform_agent_action(
1225 name_to_tool_map, color_mapping, agent_action, run_manager
1226 )

/usr/local/lib/python3.10/dist-packages/langchain/agents/agent.py in _perform_agent_action(self, name_to_tool_map, color_mapping, agent_action, run_manager)
1244 tool_run_kwargs["llm_prefix"] = ""
1245 # We then call the tool on the tool input to get an observation
-> 1246 observation = tool.run(
1247 agent_action.tool_input,
1248 verbose=self.verbose,

/usr/local/lib/python3.10/dist-packages/langchain_core/tools.py in run(self, tool_input, verbose, start_color, color, callbacks, tags, metadata, run_name, run_id, config, **kwargs)
450 except (Exception, KeyboardInterrupt) as e:
451 run_manager.on_tool_error(e)
--> 452 raise e
453 else:
454 run_manager.on_tool_end(observation, color=color, name=self.name, **kwargs)

/usr/local/lib/python3.10/dist-packages/langchain_core/tools.py in run(self, tool_input, verbose, start_color, color, callbacks, tags, metadata, run_name, run_id, config, **kwargs)
407 tool_args, tool_kwargs = self._to_args_and_kwargs(parsed_input)
408 observation = (
--> 409 context.run(
410 self._run, *tool_args, run_manager=run_manager, **tool_kwargs
411 )

/usr/local/lib/python3.10/dist-packages/langchain_community/tools/office365/send_event.py in _run(self, body, attendees, subject, start_datetime, end_datetime, run_manager)
74 event.body = body
75 event.subject = subject
---> 76 event.start = dt.strptime(start_datetime, UTC_FORMAT)
77 event.end = dt.strptime(end_datetime, UTC_FORMAT)
78 for attendee in attendees:

/usr/local/lib/python3.10/dist-packages/O365/calendar.py in start(self, value)
1070 else:
1071 if not isinstance(value.tzinfo, ZoneInfo):
-> 1072 raise ValueError('TimeZone data must be set using ZoneInfo objects')
1073 self.__start = value
1074 if not self.end:

ValueError: TimeZone data must be set using ZoneInfo objects

@RogerSelwyn
Copy link
Contributor

RogerSelwyn commented Apr 8, 2025

I certainly have no issue creating events, that said I suspect the issue should be raised here - https://github.com/langchain-ai/langchain/issues

Those dates are wrong for the O365 code base which expects python datetime objects not strings. The agent is sending:

Invoking: send_event with {'body': 'Reminder to recall John', 'attendees': ['John'], 'subject': 'Recall John', 'start_datetime': '2024-06-07T12:00:00+00:00', 'end_datetime': '2024-06-07T13:00:00+00:00'}

O365 expects datetime as shown below:

    @start.setter
    def start(self, value):
        if not isinstance(value, dt.date):
            raise ValueError("'start' must be a valid datetime object")
        if not isinstance(value, dt.datetime):
            # force datetime
            value = dt.datetime(value.year, value.month, value.day)
        if value.tzinfo is None:
            # localize datetime
            value = value.replace(tzinfo=self.protocol.timezone)
        else:
            if not isinstance(value.tzinfo, ZoneInfo):
                raise ValueError('TimeZone data must be set using ZoneInfo objects')
        self.__start = value
        if not self.end:
            self.end = self.__start + dt.timedelta(minutes=30)
        self._track_changes.add(self._cc('start'))

@RogerSelwyn
Copy link
Contributor

RogerSelwyn commented Apr 8, 2025

Tested through that code. The tzinfo that is created by strptime in /usr/local/lib/python3.10/dist-packages/langchain_community/tools/office365/send_event.py is of type datetime.timezone rather than ZoneInfo. The langchain_community library looks like it needs an update.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Not yet classified, needs a closer look
Projects
None yet
Development

No branches or pull requests

3 participants