feat: Simplify create_letta_messages_from_llm_response [LET-4681] (#5204)

Simplify create_letta_messages_from_llm_response
This commit is contained in:
Matthew Zhou
2025-10-07 11:14:29 -07:00
committed by Caren Thomas
parent 324933edd3
commit 20ce885e07
6 changed files with 2 additions and 31 deletions

View File

@@ -1666,10 +1666,8 @@ class LettaAgent(BaseAgent):
function_arguments={},
tool_execution_result=ToolExecutionResult(status="error"),
tool_call_id=tool_call_id,
function_call_success=False,
function_response=f"Error: request to call tool denied. User reason: {denial_reason}",
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
heartbeat_reason=f"{NON_USER_MSG_PREFIX}Continuing: user denied request to call tool.",
reasoning_content=None,
@@ -1777,10 +1775,8 @@ class LettaAgent(BaseAgent):
function_arguments=tool_args,
tool_execution_result=tool_execution_result,
tool_call_id=tool_call_id,
function_call_success=tool_execution_result.success_flag,
function_response=function_response_string,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
heartbeat_reason=heartbeat_reason,
reasoning_content=reasoning_content,

View File

@@ -502,7 +502,6 @@ class LettaAgentBatch(BaseAgent):
model=ctx.agent_state_map[agent_id].llm_config.model,
function_call_success=success_flag_map[agent_id],
timezone=ctx.agent_state_map[agent_id].timezone,
actor=self.actor,
)
batch_reqs.append(
LettaBatchRequest(
@@ -546,11 +545,9 @@ class LettaAgentBatch(BaseAgent):
function_name=tool_call_name,
function_arguments=tool_call_args,
tool_call_id=tool_call_id,
function_call_success=success_flag,
function_response=tool_exec_result,
tool_execution_result=tool_exec_result_obj,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=False,
reasoning_content=reasoning_content,
pre_computed_assistant_message_id=None,

View File

@@ -895,10 +895,8 @@ class LettaAgentV2(BaseAgentV2):
function_arguments={},
tool_execution_result=ToolExecutionResult(status="error"),
tool_call_id=tool_call_id,
function_call_success=False,
function_response=f"Error: request to call tool denied. User reason: {denial_reason}",
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
heartbeat_reason=f"{NON_USER_MSG_PREFIX}Continuing: user denied request to call tool.",
reasoning_content=None,
@@ -1013,10 +1011,8 @@ class LettaAgentV2(BaseAgentV2):
function_arguments=tool_args,
tool_execution_result=tool_execution_result,
tool_call_id=tool_call_id,
function_call_success=tool_execution_result.success_flag,
function_response=function_response_string,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
heartbeat_reason=heartbeat_reason,
reasoning_content=reasoning_content,

View File

@@ -563,10 +563,8 @@ class LettaAgentV3(LettaAgentV2):
function_arguments={},
tool_execution_result=ToolExecutionResult(status="error"),
tool_call_id=tool_call_id,
function_call_success=False,
function_response=f"Error: request to call tool denied. User reason: {denial_reason}",
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
# NOTE: we may need to change this to not have a "heartbeat" prefix for v3?
heartbeat_reason=f"{NON_USER_MSG_PREFIX}Continuing: user denied request to call tool.",
@@ -618,10 +616,8 @@ class LettaAgentV3(LettaAgentV2):
function_arguments=None,
tool_execution_result=None,
tool_call_id=None,
function_call_success=None,
function_response=None,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
heartbeat_reason=heartbeat_reason,
# NOTE: should probably rename this to `content`?
@@ -712,10 +708,8 @@ class LettaAgentV3(LettaAgentV2):
function_arguments=tool_args,
tool_execution_result=tool_execution_result,
tool_call_id=tool_call_id,
function_call_success=False,
function_response=tool_execution_result.func_return,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
heartbeat_reason=None,
reasoning_content=content,
@@ -797,10 +791,8 @@ class LettaAgentV3(LettaAgentV2):
function_arguments=tool_args,
tool_execution_result=tool_execution_result,
tool_call_id=tool_call_id,
function_call_success=tool_execution_result.success_flag,
function_response=function_response_string,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=continue_stepping,
# heartbeat_reason=heartbeat_reason,
heartbeat_reason=None,

View File

@@ -214,7 +214,6 @@ class VoiceAgent(BaseAgent):
response_text=content,
agent_id=agent_state.id,
model=agent_state.llm_config.model,
actor=self.actor,
timezone=agent_state.timezone,
)
letta_message_db_queue.extend(assistant_msgs)
@@ -273,11 +272,9 @@ class VoiceAgent(BaseAgent):
function_name=tool_call_name,
function_arguments=tool_args,
tool_call_id=tool_call_id,
function_call_success=success_flag,
function_response=tool_result,
tool_execution_result=tool_execution_result,
timezone=agent_state.timezone,
actor=self.actor,
continue_stepping=True,
)
letta_message_db_queue.extend(tool_call_messages)

View File

@@ -232,10 +232,8 @@ def create_letta_messages_from_llm_response(
function_arguments: Optional[Dict],
tool_execution_result: Optional[ToolExecutionResult],
tool_call_id: Optional[str],
function_call_success: Optional[bool],
function_response: Optional[str],
timezone: str,
actor: User,
run_id: str | None = None,
step_id: str = None,
continue_stepping: bool = False,
@@ -323,7 +321,7 @@ def create_letta_messages_from_llm_response(
if tool_execution_result is not None:
tool_message = Message(
role=MessageRole.tool,
content=[TextContent(text=package_function_response(function_call_success, function_response, timezone))],
content=[TextContent(text=package_function_response(tool_execution_result.success_flag, function_response, timezone))],
agent_id=agent_id,
model=model,
tool_calls=[],
@@ -349,8 +347,7 @@ def create_letta_messages_from_llm_response(
heartbeat_system_message = create_heartbeat_system_message(
agent_id=agent_id,
model=model,
function_call_success=function_call_success,
actor=actor,
function_call_success=(tool_execution_result.success_flag if tool_execution_result is not None else True),
timezone=timezone,
heartbeat_reason=heartbeat_reason,
run_id=run_id,
@@ -368,7 +365,6 @@ def create_heartbeat_system_message(
model: str,
function_call_success: bool,
timezone: str,
actor: User,
llm_batch_item_id: Optional[str] = None,
heartbeat_reason: Optional[str] = None,
run_id: Optional[str] = None,
@@ -396,7 +392,6 @@ def create_assistant_messages_from_openai_response(
response_text: str,
agent_id: str,
model: str,
actor: User,
timezone: str,
) -> List[Message]:
"""
@@ -412,10 +407,8 @@ def create_assistant_messages_from_openai_response(
function_arguments={DEFAULT_MESSAGE_TOOL_KWARG: response_text}, # Avoid raw string manipulation
tool_execution_result=ToolExecutionResult(status="success"),
tool_call_id=tool_call_id,
function_call_success=True,
function_response=None,
timezone=timezone,
actor=actor,
continue_stepping=False,
)