-
Notifications
You must be signed in to change notification settings - Fork 837
Open
Labels
Description
Description
Mem0Provider.invoking is called on user messages and searches for relevant memories:
search_response: MemorySearchResponse_v1_1 | MemorySearchResponse_v2 = await self.mem0_client.search(
query=input_text,
user_id=self.user_id,
agent_id=self.agent_id,
run_id=self._per_operation_thread_id if self.scope_to_per_operation_thread_id else self.thread_id,
)
A vector store search task is created:
vector_store_task = asyncio.create_task(
self._search_vector_store(query, effective_filters, limit, threshold)
)
The input text is embedded before searching:
embeddings = await asyncio.to_thread(
self.embedding_model.embed, query, "search"
)
memories = await asyncio.to_thread(
self.vector_store.search,
query=query,
vectors=embeddings,
limit=limit,
filters=filters
)
Observed Behavior
query appears to be empty ('') when a function approval response (no text attributed) is made. This results in an attempt to embed the empty string:
input_text = "\n".join(msg.text for msg in messages_list if msg and msg.text and msg.text.strip())
Error Encountered
Error in agent execution: Error code: 400 - {
'error': {
'message': "'$.input' is invalid. Please check the API reference: https://platform.openai.com/docs/api-reference.",
'type': 'invalid_request_error',
'param': None,
'code': None
}
}
Steps To Reproduce
- Define a tool that requires approval
@ai_function(
name="send_email",
description="Send an email to a recipient",
approval_mode="always_require"
)
def send_email(to: str, subject: str, body: str) -> str:
"""Send an email with the given details."""
# Email sending logic here
return f"Email sent to {to} with subject: {subject}"
- Create an agent with a Mem0 context provider
agent = ChatAgent(
chat_client=<CLIENT>,
name="assistant",
instructions="You are a helpful assistant with memory.",
context_providers=<MEM0_PROVIDER>,
tools=[send_email]
)
- Run the agent and approve the tool call
async with agent:
# Run the agent and handle approvals
result = await agent.run("Send a test email to example@example.com")
# Handle any approval requests
while len(result.user_input_requests) > 0:
for user_input_needed in result.user_input_requests:
print(f"Approval needed for: {user_input_needed.function_call.name}")
user_approval = input("Approve? (y/n): ")
# Send approval response back to agent
result = await agent.run([
ChatMessage(
role="user",
contents=[user_input_needed.create_response(user_approval.lower() == "y")]
)
])
print(f"Final result: {result}")
Proposed Solution
Return an empty context object when input text is missing.