When building predictive market applications askpaul.ai, transparency in data sources is crucial for user trust and informed decision-making. Our platform leverages MiroMindAI's MiroFlow for market outcome predictions, but we faced a challenge: MiroFlow didn't natively support tracking and exposing the reference data sources used in predictions.
To address this, we implemented modifications to MiroFlow (available at https://github.com/MiroMindAI/MiroFlow) that enable comprehensive tracking of tool usage across all agents involved in the prediction process.
The Modification Approach
Our solution focused on capturing and preserving tool call data throughout the prediction process, with specific changes in two key files:
1. Tracking Tool Calls in src/core/orchestrator.py
We needed to ensure tool usage data persisted across multiple rounds of agent interactions rather than being reset each time.
Sub-agent Tool Call Tracking
# Execute tool calls
# Note: Do not reinitialize tool_calls_data to accumulate data across turns
if not hasattr(self, '_sub_agent_tool_calls_data'):
self._sub_agent_tool_calls_data = []
tool_calls_data = self._sub_agent_tool_calls_data
all_tool_results_content_with_id = []
We then added identification and logging capabilities for sub-agent activities:
# Store current turn's tool call data to logs
if tool_calls_data:
# Add sub-agent identification to each tool call
for call_data in tool_calls_data:
call_data["agent_type"] = "sub_agent"
call_data["sub_agent_name"] = sub_agent_name
# Store only newly added data to avoid duplicates
current_turn_data = [call_data for call_data in tool_calls_data if call_data not in self.task_log.tool_calls_data]
self.task_log.tool_calls_data.extend(current_turn_data)
Main Agent Tool Call Tracking
Similar modifications were made for the main agent:
# 7. Execute tool calls (in sequence)
# Note: Do not reinitialize tool_calls_data to accumulate data across turns
if not hasattr(self, '_main_agent_tool_calls_data'):
self._main_agent_tool_calls_data = []
tool_calls_data = self._main_agent_tool_calls_data
all_tool_results_content_with_id = []
With corresponding logging:
# Store main agent's tool call data to logs
if tool_calls_data:
# Add main agent identification to each tool call
for call_data in tool_calls_data:
call_data["agent_type"] = "main_agent"
# Store only newly added data to avoid duplicates
current_turn_data = [call_data for call_data in tool_calls_data if call_data not in self.task_log.tool_calls_data]
self.task_log.tool_calls_data.extend(current_turn_data)
2. Extending Logging Capabilities in src/logging/task_tracer.py
To accommodate the new tracking data, we added a dedicated field in the task logging structure:
step_logs: list[StepRecord] = Field(default_factory=list)
# Store detailed data for all tool calls
tool_calls_data: list[dict[str, Any]] = Field(default_factory=list)
Key Improvements
These modifications delivered several critical enhancements:
Data Persistence: Tool call data is now stored in instance variables rather than temporary variables, preventing data loss between rounds.
Cross-turn Accumulation: The system now maintains a complete history of tool usage across all interaction rounds.
Agent Identification: Each tool call is clearly marked as originating from either the main agent or a specific sub-agent.
Integrated Logging: All tool usage data is systematically stored in the task log for later retrieval and display.
Duplicate Prevention: A deduplication mechanism ensures each tool call is recorded only once.
These changes have transformed MiroFlow into a more transparent prediction engine, allowing applications like askpaul.ai to display comprehensive data source information to users. This not only enhances user trust but also provides valuable insights into how predictions are formulated.
By making these modifications open-source, we hope to contribute to the MiroMindAI community and help other developers building transparent AI-powered applications.
Top comments (0)