Query using MIRIX native send_message (recommended). This leverages MIRIX's built-in memory retrieval and conversation capabilities, providing a more integrated experience.
(
self,
question: str,
system_message: Optional[str],
start_time: float
)
| 703 | return self._query_manual(question, system_message, start_time) |
| 704 | |
| 705 | def _query_native( |
| 706 | self, |
| 707 | question: str, |
| 708 | system_message: Optional[str], |
| 709 | start_time: float |
| 710 | ) -> AgentResponse: |
| 711 | """Query using MIRIX native send_message (recommended). |
| 712 | |
| 713 | This leverages MIRIX's built-in memory retrieval and conversation |
| 714 | capabilities, providing a more integrated experience. |
| 715 | """ |
| 716 | # Truncate question |
| 717 | full_question = self._truncate_to_tokens(question, self.max_question_tokens) |
| 718 | |
| 719 | # Add timestamp for context |
| 720 | query_with_time = f"{full_question}\n\nCurrent Time: {time.strftime('%Y-%m-%d %H:%M:%S')}" |
| 721 | |
| 722 | # If there's a system message, prepend it as context |
| 723 | if system_message: |
| 724 | query_with_context = f"[System Context: {system_message}]\n\n{query_with_time}" |
| 725 | else: |
| 726 | query_with_context = query_with_time |
| 727 | |
| 728 | response_content = "" |
| 729 | retrieved_memories = [] |
| 730 | query_usage = {"input": 0, "output": 0} |
| 731 | |
| 732 | async def do_query(): |
| 733 | nonlocal response_content, retrieved_memories, query_usage |
| 734 | |
| 735 | # Use MIRIX native send_message - it will automatically retrieve |
| 736 | # relevant memories and use them in the response |
| 737 | # NOTE: We don't pass user_id - MIRIX uses LocalClient's default user |
| 738 | response = await self._client.send_message( |
| 739 | agent_id=self._meta_agent.id, |
| 740 | role="user", |
| 741 | message=query_with_context, |
| 742 | ) |
| 743 | |
| 744 | # Extract response content and usage |
| 745 | if response: |
| 746 | # Record usage to global tracker |
| 747 | if hasattr(response, 'usage') and response.usage: |
| 748 | self._record_mirix_usage(response.usage, time.time() - start_time) |
| 749 | query_usage["input"] = getattr(response.usage, 'prompt_tokens', 0) |
| 750 | query_usage["output"] = getattr(response.usage, 'completion_tokens', 0) |
| 751 | |
| 752 | # Extract assistant response |
| 753 | if hasattr(response, 'messages'): |
| 754 | for msg in response.messages: |
| 755 | msg_type = getattr(msg, 'message_type', '') |
| 756 | if msg_type == "assistant_message": |
| 757 | response_content = getattr(msg, 'message', '') |
| 758 | break |
| 759 | |
| 760 | # Also extract any function calls that retrieved memories |
| 761 | for msg in response.messages: |
| 762 | msg_type = getattr(msg, 'message_type', '') |
no test coverage detected