|
67 | 67 | _agents_updated: dict[str, datetime] = {} |
68 | 68 |
|
69 | 69 |
|
| 70 | +def _extract_text_content(content: object) -> str: |
| 71 | + if isinstance(content, list): |
| 72 | + texts: list[str] = [] |
| 73 | + for item in content: |
| 74 | + if isinstance(item, dict): |
| 75 | + t = item.get("text") |
| 76 | + ty = item.get("type") |
| 77 | + if t is not None and (ty == "text" or ty is None): |
| 78 | + texts.append(t) |
| 79 | + elif isinstance(item, str): |
| 80 | + texts.append(item) |
| 81 | + return "".join(texts) |
| 82 | + if isinstance(content, dict): |
| 83 | + if content.get("type") == "text" and "text" in content: |
| 84 | + return content["text"] |
| 85 | + if "text" in content: |
| 86 | + return content["text"] |
| 87 | + return "" |
| 88 | + if isinstance(content, str): |
| 89 | + return content |
| 90 | + return "" |
| 91 | + |
| 92 | + |
70 | 93 | async def build_agent( |
71 | 94 | agent: Agent, agent_data: AgentData, custom_skills: list[BaseTool] = [] |
72 | 95 | ) -> CompiledStateGraph: |
@@ -149,8 +172,8 @@ async def select_model( |
149 | 172 | if llm_model.info.provider == LLMProvider.OPENAI: |
150 | 173 | tools.append({"type": "web_search"}) |
151 | 174 | private_tools.append({"type": "web_search"}) |
152 | | - if agent.model.startswith("gpt-5-"): |
153 | | - llm_params["reasoning_effort"] = "low" |
| 175 | + if llm_model.info.model_name == "gpt-5-mini": |
| 176 | + llm_params["reasoning_effort"] = "medium" |
154 | 177 | if llm_model.info.provider == LLMProvider.XAI: |
155 | 178 | llm_params["search_parameters"] = {"mode": "auto"} |
156 | 179 | # TODO: else use a search skill |
@@ -431,31 +454,30 @@ async def stream_agent_raw( |
431 | 454 |
|
432 | 455 | # super mode |
433 | 456 | recursion_limit = 30 |
434 | | - if re.search(r"\b@super\b", input_message): |
| 457 | + if re.search(r"@super\b", input_message) or user_message.super_mode: |
435 | 458 | recursion_limit = 300 |
436 | 459 | # Remove @super from the message |
437 | | - input_message = re.sub(r"\b@super\b", "", input_message).strip() |
| 460 | + input_message = re.sub(r"@super\b", "", input_message).strip() |
438 | 461 |
|
439 | 462 | # llm native search |
440 | | - search = False |
441 | | - if re.search(r"\b@search\b", input_message) or re.search( |
442 | | - r"\b@web\b", input_message |
443 | | - ): |
| 463 | + search = user_message.search_mode if user_message.search_mode is not None else False |
| 464 | + if re.search(r"@search\b", input_message) or re.search(r"@web\b", input_message): |
444 | 465 | search = True |
445 | 466 | if model.supports_search: |
446 | 467 | input_message = re.sub( |
447 | | - r"\b@search\b", |
| 468 | + r"@search\b", |
448 | 469 | "(You have native search tool, you can use it to get more recent information)", |
449 | 470 | input_message, |
450 | 471 | ).strip() |
451 | 472 | input_message = re.sub( |
452 | | - r"\b@web\b", |
| 473 | + r"@web\b", |
453 | 474 | "(You have native search tool, you can use it to get more recent information)", |
454 | 475 | input_message, |
455 | 476 | ).strip() |
456 | 477 | else: |
457 | | - input_message = re.sub(r"\b@search\b", "", input_message).strip() |
458 | | - input_message = re.sub(r"\b@web\b", "", input_message).strip() |
| 478 | + search = False |
| 479 | + input_message = re.sub(r"@search\b", "", input_message).strip() |
| 480 | + input_message = re.sub(r"@web\b", "", input_message).strip() |
459 | 481 |
|
460 | 482 | # content to llm |
461 | 483 | messages = [ |
@@ -526,16 +548,7 @@ def get_agent() -> Agent: |
526 | 548 | # tool calls, save for later use, if it is deleted by post_model_hook, will not be used. |
527 | 549 | cached_tool_step = msg |
528 | 550 | if hasattr(msg, "content") and msg.content: |
529 | | - content = msg.content |
530 | | - if isinstance(msg.content, list): |
531 | | - # in new version, content item maybe a list |
532 | | - content = msg.content[0] |
533 | | - if isinstance(content, dict): |
534 | | - if "text" in content: |
535 | | - content = content["text"] |
536 | | - else: |
537 | | - content = str(content) |
538 | | - logger.error(f"unexpected content type: {content}") |
| 551 | + content = _extract_text_content(msg.content) |
539 | 552 | # agent message |
540 | 553 | chat_message_create = ChatMessageCreate( |
541 | 554 | id=str(XID()), |
|
0 commit comments