Skip to content
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

fix: Check that content is not None before setting to internal_monologue #1813

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions letta/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,18 +551,15 @@ def _handle_ai_response(
) # extend conversation with assistant's reply
printd(f"Function call message: {messages[-1]}")

# The content if then internal monologue, not chat
self.interface.internal_monologue(response_message.content, msg_obj=messages[-1])
mattzh72 marked this conversation as resolved.
Show resolved Hide resolved

# Step 3: call the function
# Note: the JSON response may not always be valid; be sure to handle errors

# Failure case 1: function name is wrong
function_call = (
response_message.function_call if response_message.function_call is not None else response_message.tool_calls[0].function
)
function_name = function_call.name
printd(f"Request to call function {function_name} with tool_call_id: {tool_call_id}")

# Failure case 1: function name is wrong
try:
function_to_call = self.functions_python[function_name]
except KeyError:
Expand Down Expand Up @@ -607,6 +604,13 @@ def _handle_ai_response(
self.interface.function_message(f"Error: {error_msg}", msg_obj=messages[-1])
return messages, False, True # force a heartbeat to allow agent to handle error

# Community noted that inner thoughts can sometimes appear in the function args
mattzh72 marked this conversation as resolved.
Show resolved Hide resolved
if "inner_thoughts" in function_args:
response_message.content = function_args.pop("inner_thoughts")
if response_message.content:
# The content if then internal monologue, not chat
self.interface.internal_monologue(response_message.content, msg_obj=messages[-1])

# (Still parsing function args)
# Handle requests for immediate heartbeat
heartbeat_request = function_args.pop("request_heartbeat", None)
Expand Down
Loading