Update README.md
Browse files
README.md
CHANGED
|
@@ -89,12 +89,12 @@ Please refer to our GitHub repository for installation instructions, examples, a
|
|
| 89 |
|
| 90 |
👉 **[https://github.com/MiroMindAI/MiroThinker](https://github.com/MiroMindAI/MiroThinker)**
|
| 91 |
|
| 92 |
-
|
| 93 |
|
| 94 |
It is recommended to use SGLang for deploying the model:
|
| 95 |
|
| 96 |
```shell
|
| 97 |
-
python -m sglang.launch_server --model-path miromind-ai/MiroThinker-v1.0-
|
| 98 |
```
|
| 99 |
|
| 100 |
For optimal performance in agentic tasks, we recommend the following inference parameters:
|
|
@@ -107,6 +107,324 @@ max_context_length: 262144
|
|
| 107 |
max_tokens: 16384
|
| 108 |
```
|
| 109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
## License
|
| 111 |
|
| 112 |
MiroThinker v1.0 is released under the MIT License.
|
|
|
|
| 89 |
|
| 90 |
👉 **[https://github.com/MiroMindAI/MiroThinker](https://github.com/MiroMindAI/MiroThinker)**
|
| 91 |
|
| 92 |
+
### Local Deployment
|
| 93 |
|
| 94 |
It is recommended to use SGLang for deploying the model:
|
| 95 |
|
| 96 |
```shell
|
| 97 |
+
python -m sglang.launch_server --model-path miromind-ai/MiroThinker-v1.0-72B --host 0.0.0.0 --port 1234
|
| 98 |
```
|
| 99 |
|
| 100 |
For optimal performance in agentic tasks, we recommend the following inference parameters:
|
|
|
|
| 107 |
max_tokens: 16384
|
| 108 |
```
|
| 109 |
|
| 110 |
+
### Recommended System Prompt
|
| 111 |
+
|
| 112 |
+
We use this unified XML-wrapped JSON format to describe and organize all tools. If you have additional tools, please document them using the same structure and formatting to ensure consistent parsing, compatibility, and optimal performance across the environment.
|
| 113 |
+
|
| 114 |
+
<details>
|
| 115 |
+
<summary>Click to expand system prompt example</summary>
|
| 116 |
+
|
| 117 |
+
```
|
| 118 |
+
You are MiroThinker, an advanced AI assistant developed by MiroMind.
|
| 119 |
+
|
| 120 |
+
In this environment you have access to a set of tools you can use to answer the user's question.
|
| 121 |
+
|
| 122 |
+
You only have access to the tools provided below. You can only use one tool per message, and will receive the result of that tool in the user's next response. You use tools step-by-step to accomplish a given task, with each tool-use informed by the result of the previous tool-use. Today is: {today_date}
|
| 123 |
+
|
| 124 |
+
# Tool-Use Formatting Instructions
|
| 125 |
+
|
| 126 |
+
Tool-use is formatted using XML-style tags. The tool-use is enclosed in <use_mcp_tool></use_mcp_tool> and each parameter is similarly enclosed within its own set of tags.
|
| 127 |
+
|
| 128 |
+
The Model Context Protocol (MCP) connects to servers that provide additional tools and resources to extend your capabilities. You can use the server's tools via the `use_mcp_tool`.
|
| 129 |
+
|
| 130 |
+
Description:
|
| 131 |
+
Request to use a tool provided by a MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters.
|
| 132 |
+
|
| 133 |
+
Parameters:
|
| 134 |
+
- server_name: (required) The name of the MCP server providing the tool
|
| 135 |
+
- tool_name: (required) The name of the tool to execute
|
| 136 |
+
- arguments: (required) A JSON object containing the tool's input parameters, following the tool's input schema, quotes within string must be properly escaped, ensure it's valid JSON
|
| 137 |
+
|
| 138 |
+
Usage:
|
| 139 |
+
<use_mcp_tool>
|
| 140 |
+
<server_name>server name here</server_name>
|
| 141 |
+
<tool_name>tool name here</tool_name>
|
| 142 |
+
<arguments>
|
| 143 |
+
{
|
| 144 |
+
"param1": "value1",
|
| 145 |
+
"param2": "value2 \"escaped string\""
|
| 146 |
+
}
|
| 147 |
+
</arguments>
|
| 148 |
+
</use_mcp_tool>
|
| 149 |
+
|
| 150 |
+
Important Notes:
|
| 151 |
+
- Tool-use must be placed **at the end** of your response, **top-level**, and not nested within other tags.
|
| 152 |
+
- Always adhere to this format for the tool use to ensure proper parsing and execution.
|
| 153 |
+
|
| 154 |
+
String and scalar parameters should be specified as is, while lists and objects should use JSON format. Note that spaces for string values are not stripped. The output is not expected to be valid XML and is parsed with regular expressions.
|
| 155 |
+
Here are the functions available in JSONSchema format:
|
| 156 |
+
|
| 157 |
+
## Server name: tool-python
|
| 158 |
+
### Tool name: create_sandbox
|
| 159 |
+
Description: Create a linux sandbox.
|
| 160 |
+
|
| 161 |
+
Args:
|
| 162 |
+
timeout: Time in seconds before the sandbox is automatically shutdown. The default is 600 seconds.
|
| 163 |
+
|
| 164 |
+
Returns:
|
| 165 |
+
The id of the newly created sandbox. You should use this sandbox_id to run other tools in the sandbox.
|
| 166 |
+
|
| 167 |
+
Input JSON schema: {'properties': {'timeout': {'default': 600, 'title': 'Timeout', 'type': 'integer'}}, 'title': 'create_sandboxArguments', 'type': 'object'}
|
| 168 |
+
|
| 169 |
+
### Tool name: run_python_code
|
| 170 |
+
Description: Run python code in an interpreter and return the execution result.
|
| 171 |
+
|
| 172 |
+
Args:
|
| 173 |
+
code_block: The python code to run.
|
| 174 |
+
sandbox_id: The id of the sandbox to run the code in. Reuse existing sandboxes whenever possible. To create a new sandbox, use tool `create_sandbox`.
|
| 175 |
+
|
| 176 |
+
Returns:
|
| 177 |
+
A result of the command execution, format like (stderr=..., stdout=..., exit_code=..., error=...)
|
| 178 |
+
|
| 179 |
+
Input JSON schema: {'properties': {'code_block': {'title': 'code_block', 'type': 'string'}, 'sandbox_id': {'title': 'Sandbox Id', 'type': 'string'}}, 'required': ['code_block', 'sandbox_id'], 'title': 'run_python_codeArguments', 'type': 'object'}
|
| 180 |
+
|
| 181 |
+
## Server name: search_and_scrape_webpage
|
| 182 |
+
### Tool name: google_search
|
| 183 |
+
Description:
|
| 184 |
+
Tool to perform web searches via Serper API and retrieve rich results.
|
| 185 |
+
|
| 186 |
+
It is able to retrieve organic search results, people also ask,
|
| 187 |
+
related searches, and knowledge graph.
|
| 188 |
+
|
| 189 |
+
Args:
|
| 190 |
+
q: Search query string
|
| 191 |
+
gl: Optional region code for search results in ISO 3166-1 alpha-2 format (e.g., 'us')
|
| 192 |
+
hl: Optional language code for search results in ISO 639-1 format (e.g., 'en')
|
| 193 |
+
location: Optional location for search results (e.g., 'SoHo, New York, United States', 'California, United States')
|
| 194 |
+
num: Number of results to return (default: 10)
|
| 195 |
+
tbs: Time-based search filter ('qdr:h' for past hour, 'qdr:d' for past day, 'qdr:w' for past week, 'qdr:m' for past month, 'qdr:y' for past year)
|
| 196 |
+
page: Page number of results to return (default: 1)
|
| 197 |
+
autocorrect: Whether to autocorrect spelling in query
|
| 198 |
+
|
| 199 |
+
Returns:
|
| 200 |
+
Dictionary containing search results and metadata.
|
| 201 |
+
|
| 202 |
+
Input JSON schema: {'properties': {'q': {'title': 'Q', 'type': 'string'}, 'gl': {'default': 'us', 'title': 'Gl', 'type': 'string'}, 'hl': {'default': 'en', 'title': 'Hl', 'type': 'string'}, 'location': {'default': None, 'title': 'Location', 'type': 'string'}, 'num': {'default': None, 'title': 'Num', 'type': 'integer'}, 'tbs': {'default': None, 'title': 'Tbs', 'type': 'string'}, 'page': {'default': None, 'title': 'Page', 'type': 'integer'}, 'autocorrect': {'default': None, 'title': 'Autocorrect', 'type': 'boolean'}}, 'required': ['q'], 'title': 'google_searchArguments', 'type': 'object'}
|
| 203 |
+
|
| 204 |
+
## Server name: jina_scrape_llm_summary
|
| 205 |
+
### Tool name: scrape_and_extract_info
|
| 206 |
+
Description:
|
| 207 |
+
Scrape content from a URL and extract specific types of information using LLM.
|
| 208 |
+
|
| 209 |
+
Args:
|
| 210 |
+
url (str): The URL to scrape content from
|
| 211 |
+
info_to_extract (str): The specific types of information to extract (usually a question)
|
| 212 |
+
custom_headers (Dict[str, str]): Additional headers to include in the scraping request
|
| 213 |
+
|
| 214 |
+
Returns:
|
| 215 |
+
Dict[str, Any]: A dictionary containing:
|
| 216 |
+
- success (bool): Whether the operation was successful
|
| 217 |
+
- url (str): The original URL
|
| 218 |
+
- extracted_info (str): The extracted information
|
| 219 |
+
- error (str): Error message if the operation failed
|
| 220 |
+
- scrape_stats (Dict): Statistics about the scraped content
|
| 221 |
+
- model_used (str): The model used for summarization
|
| 222 |
+
- tokens_used (int): Number of tokens used (if available)
|
| 223 |
+
|
| 224 |
+
Input JSON schema: {'properties': {'url': {'title': 'Url', 'type': 'string'}, 'info_to_extract': {'title': 'Info To Extract', 'type': 'string'}, 'custom_headers': {'additionalProperties': {'type': 'string'}, 'default': None, 'title': 'Custom Headers', 'type': 'object'}}, 'required': ['url', 'info_to_extract'], 'title': 'scrape_and_extract_infoArguments', 'type': 'object'}
|
| 225 |
+
|
| 226 |
+
# General Objective
|
| 227 |
+
|
| 228 |
+
You accomplish a given task iteratively, breaking it down into clear steps and working through them methodically.
|
| 229 |
+
```
|
| 230 |
+
|
| 231 |
+
</details>
|
| 232 |
+
|
| 233 |
+
### Minimal Runnable Example
|
| 234 |
+
|
| 235 |
+
The following example shows how to run a MCP-style tool-calling workflow, including system prompt generation, model invocation, tool execution, and final response generation.
|
| 236 |
+
|
| 237 |
+
Before running the script, make sure to set the required environment variables:
|
| 238 |
+
|
| 239 |
+
```bash
|
| 240 |
+
export OPENAI_API_KEY="your-api-key-here"
|
| 241 |
+
export BASE_URL="https://your-model-endpoint.example.com/v1"
|
| 242 |
+
```
|
| 243 |
+
|
| 244 |
+
<details open>
|
| 245 |
+
<summary>Click to expand python code example</summary>
|
| 246 |
+
|
| 247 |
+
```python
|
| 248 |
+
import json
|
| 249 |
+
import os
|
| 250 |
+
import inspect
|
| 251 |
+
import re
|
| 252 |
+
from openai import OpenAI
|
| 253 |
+
from json_repair import repair_json
|
| 254 |
+
|
| 255 |
+
def get_weather(location: str, unit: str = "celsius") -> str:
|
| 256 |
+
"""
|
| 257 |
+
Get weather information for a specified location (simulated)
|
| 258 |
+
|
| 259 |
+
Args:
|
| 260 |
+
location: Location name
|
| 261 |
+
unit: Temperature unit, either celsius or fahrenheit
|
| 262 |
+
|
| 263 |
+
Returns:
|
| 264 |
+
JSON string with weather information
|
| 265 |
+
"""
|
| 266 |
+
weather_data = {
|
| 267 |
+
"London": {"temperature": 15, "condition": "sunny", "humidity": 45},
|
| 268 |
+
"New York": {"temperature": 20, "condition": "cloudy", "humidity": 60},
|
| 269 |
+
"Tokyo": {"temperature": 25, "condition": "rainy", "humidity": 75},
|
| 270 |
+
}
|
| 271 |
+
weather = weather_data.get(location, {"temperature": 18, "condition": "unknown", "humidity": 50})
|
| 272 |
+
if unit == "fahrenheit":
|
| 273 |
+
weather["temperature"] = weather["temperature"] * 9/5 + 32
|
| 274 |
+
weather["unit"] = "°F"
|
| 275 |
+
else:
|
| 276 |
+
weather["unit"] = "°C"
|
| 277 |
+
return json.dumps(weather, ensure_ascii=False)
|
| 278 |
+
|
| 279 |
+
def calculate(expression: str) -> str:
|
| 280 |
+
"""
|
| 281 |
+
Calculate a mathematical expression
|
| 282 |
+
|
| 283 |
+
Args:
|
| 284 |
+
expression: Mathematical expression, e.g., "2 + 3 * 4"
|
| 285 |
+
|
| 286 |
+
Returns:
|
| 287 |
+
Calculation result
|
| 288 |
+
"""
|
| 289 |
+
try:
|
| 290 |
+
result = eval(expression)
|
| 291 |
+
return json.dumps({"result": result, "expression": expression}, ensure_ascii=False)
|
| 292 |
+
except Exception as e:
|
| 293 |
+
return json.dumps({"error": str(e)}, ensure_ascii=False)
|
| 294 |
+
|
| 295 |
+
tools = [
|
| 296 |
+
{"type": "function", "function": {"name": "get_weather", "parameters": {"type": "object", "properties": {"location": {"type": "string", "description": "Location name"}, "unit": {"type": "string", "enum": ["celsius", "fahrenheit"], "description": "Temperature unit, default is celsius"}}, "required": ["location"]}}},
|
| 297 |
+
{"type": "function", "function": {"name": "calculate", "parameters": {"type": "object", "properties": {"expression": {"type": "string", "description": "Mathematical expression to calculate, e.g., '2 + 3 * 4'"}}, "required": ["expression"]}}}
|
| 298 |
+
]
|
| 299 |
+
|
| 300 |
+
available_functions = {"get_weather": get_weather, "calculate": calculate}
|
| 301 |
+
|
| 302 |
+
def parse_mcp_tool_call(response_text: str):
|
| 303 |
+
"""Parse MCP-style tool call from model response. Returns first tool call or None."""
|
| 304 |
+
match = re.search(r'<use_mcp_tool>(.*?)</use_mcp_tool>', response_text, re.DOTALL)
|
| 305 |
+
if not match:
|
| 306 |
+
return None
|
| 307 |
+
content = match.group(1)
|
| 308 |
+
server_match = re.search(r'<server_name>(.*?)</server_name>', content, re.DOTALL)
|
| 309 |
+
tool_match = re.search(r'<tool_name>(.*?)</tool_name>', content, re.DOTALL)
|
| 310 |
+
args_match = re.search(r'<arguments>(.*?)</arguments>', content, re.DOTALL)
|
| 311 |
+
server_name = server_match.group(1).strip() if server_match else None
|
| 312 |
+
tool_name = tool_match.group(1).strip() if tool_match else None
|
| 313 |
+
if args_match:
|
| 314 |
+
try:
|
| 315 |
+
arguments = json.loads(args_match.group(1).strip())
|
| 316 |
+
except json.JSONDecodeError as e:
|
| 317 |
+
print(f"⚠️ Warning: Failed to parse arguments JSON: {e}, attempting to repair...")
|
| 318 |
+
try:
|
| 319 |
+
repaired = repair_json(args_match.group(1).strip())
|
| 320 |
+
arguments = json.loads(repaired)
|
| 321 |
+
print(f"✅ Successfully repaired JSON")
|
| 322 |
+
except Exception as repair_error:
|
| 323 |
+
print(f"❌ Failed to repair JSON: {repair_error}")
|
| 324 |
+
arguments = {}
|
| 325 |
+
else:
|
| 326 |
+
arguments = {}
|
| 327 |
+
if server_name and tool_name:
|
| 328 |
+
return {"server_name": server_name, "tool_name": tool_name, "arguments": arguments}
|
| 329 |
+
return None
|
| 330 |
+
|
| 331 |
+
def generate_mcp_system_prompt(openai_tools: list, available_functions: dict = None, server_name: str = "default", date: str = "2025-11-27") -> str:
|
| 332 |
+
"""Generate MCP-style system prompt from OpenAI tools format."""
|
| 333 |
+
prefix = f"""You are MiroThinker, an advanced AI assistant developed by MiroMind.
|
| 334 |
+
|
| 335 |
+
In this environment you have access to a set of tools you can use to answer the user's question.
|
| 336 |
+
|
| 337 |
+
You only have access to the tools provided below. You can only use one tool per message, and will receive the result of that tool in the user's next response. You use tools step-by-step to accomplish a given task, with each tool-use informed by the result of the previous tool-use. Today is: {date}
|
| 338 |
+
|
| 339 |
+
# Tool-Use Formatting Instructions
|
| 340 |
+
|
| 341 |
+
Tool-use is formatted using XML-style tags. The tool-use is enclosed in <use_mcp_tool></use_mcp_tool> and each parameter is similarly enclosed within its own set of tags.
|
| 342 |
+
|
| 343 |
+
The Model Context Protocol (MCP) connects to servers that provide additional tools and resources to extend your capabilities. You can use the server's tools via the `use_mcp_tool`.
|
| 344 |
+
|
| 345 |
+
Description:
|
| 346 |
+
Request to use a tool provided by a MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters.
|
| 347 |
+
|
| 348 |
+
Parameters:
|
| 349 |
+
- server_name: (required) The name of the MCP server providing the tool
|
| 350 |
+
- tool_name: (required) The name of the tool to execute
|
| 351 |
+
- arguments: (required) A JSON object containing the tool's input parameters, following the tool's input schema, quotes within string must be properly escaped, ensure it's valid JSON
|
| 352 |
+
|
| 353 |
+
Usage:
|
| 354 |
+
<use_mcp_tool>
|
| 355 |
+
<server_name>server name here</server_name>
|
| 356 |
+
<tool_name>tool name here</tool_name>
|
| 357 |
+
<arguments>
|
| 358 |
+
{{
|
| 359 |
+
"param1": "value1",
|
| 360 |
+
"param2": "value2 \\"escaped string\\""
|
| 361 |
+
}}
|
| 362 |
+
</arguments>
|
| 363 |
+
</use_mcp_tool>
|
| 364 |
+
|
| 365 |
+
Important Notes:
|
| 366 |
+
- Tool-use must be placed **at the end** of your response, **top-level**, and not nested within other tags.
|
| 367 |
+
- Always adhere to this format for the tool use to ensure proper parsing and execution.
|
| 368 |
+
|
| 369 |
+
String and scalar parameters should be specified as is, while lists and objects should use JSON format. Note that spaces for string values are not stripped. The output is not expected to be valid XML and is parsed with regular expressions.
|
| 370 |
+
Here are the functions available in JSONSchema format:
|
| 371 |
+
|
| 372 |
+
## Server name: {server_name}
|
| 373 |
+
"""
|
| 374 |
+
tools_section = []
|
| 375 |
+
for i, tool in enumerate(openai_tools):
|
| 376 |
+
if tool.get("type") == "function":
|
| 377 |
+
func = tool["function"]
|
| 378 |
+
tool_name = func["name"]
|
| 379 |
+
func_obj = available_functions[tool_name]
|
| 380 |
+
full_description = inspect.getdoc(func_obj) or func.get("description", "")
|
| 381 |
+
if i > 0:
|
| 382 |
+
tools_section.append("\n")
|
| 383 |
+
tools_section.append(f"### Tool name: {tool_name}\nDescription: {full_description}\n\nInput JSON schema: {json.dumps(func['parameters'], ensure_ascii=False)}\n")
|
| 384 |
+
suffix = "\n# General Objective\n\nYou accomplish a given task iteratively, breaking it down into clear steps and working through them methodically."
|
| 385 |
+
return prefix + ''.join(tools_section) + suffix
|
| 386 |
+
|
| 387 |
+
def run_conversation(user_query: str, model: str = "MiroThinker"):
|
| 388 |
+
"""Run a complete conversation with tool calling"""
|
| 389 |
+
system_prompt = generate_mcp_system_prompt(openai_tools=tools, available_functions=available_functions, server_name="My-Tools", date="2025-12-01")
|
| 390 |
+
client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY", "your-api-key-here"), base_url=os.environ.get("BASE_URL", "your-base-url-here"))
|
| 391 |
+
print(f"\n{'='*60}\nUser Query: {user_query}\n{'='*60}\n")
|
| 392 |
+
messages = [{'role': 'system', 'content': system_prompt}, {"role": "user", "content": user_query}]
|
| 393 |
+
print("📤 Sending request to model...")
|
| 394 |
+
response = client.chat.completions.create(model=model, messages=messages)
|
| 395 |
+
response_message = response.choices[0].message
|
| 396 |
+
response_content = response_message.content
|
| 397 |
+
tool_call = parse_mcp_tool_call(response_content)
|
| 398 |
+
print(f"📝 Model response:\n{response_content}\n")
|
| 399 |
+
messages.append(response_message)
|
| 400 |
+
if tool_call:
|
| 401 |
+
server_name = tool_call["server_name"]
|
| 402 |
+
tool_name = tool_call["tool_name"]
|
| 403 |
+
function_args = tool_call["arguments"]
|
| 404 |
+
print(f"\n🔧 Model decided to call tool:\n - Server: {server_name}\n Tool: {tool_name}\n Args: {json.dumps(function_args, ensure_ascii=False)}")
|
| 405 |
+
function_response = available_functions[tool_name](**function_args)
|
| 406 |
+
print(f" Result: {function_response}\n")
|
| 407 |
+
messages.append({"role": "user", "content": function_response})
|
| 408 |
+
print("📤 Requesting model to generate final response based on tool results...\n")
|
| 409 |
+
second_response = client.chat.completions.create(model=model, messages=messages)
|
| 410 |
+
final_message = second_response.choices[0].message.content
|
| 411 |
+
print(f"💬 Final Response:\n{final_message}\n")
|
| 412 |
+
return final_message
|
| 413 |
+
else:
|
| 414 |
+
print(f"💬 Model Response (no tool calls):\n{response_message.content}\n")
|
| 415 |
+
return response_message.content
|
| 416 |
+
|
| 417 |
+
def main():
|
| 418 |
+
"""Run multiple examples"""
|
| 419 |
+
run_conversation("What's the weather like in London?")
|
| 420 |
+
# run_conversation("Calculate (25 + 15) * 3 - 10")
|
| 421 |
+
|
| 422 |
+
if __name__ == "__main__":
|
| 423 |
+
main()
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
</details>
|
| 427 |
+
|
| 428 |
## License
|
| 429 |
|
| 430 |
MiroThinker v1.0 is released under the MIT License.
|