Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 35 additions & 22 deletions intentkit/core/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,29 @@
_agents_updated: dict[str, datetime] = {}


def _extract_text_content(content: object) -> str:
if isinstance(content, list):
texts: list[str] = []
for item in content:
if isinstance(item, dict):
t = item.get("text")
ty = item.get("type")
if t is not None and (ty == "text" or ty is None):
texts.append(t)
elif isinstance(item, str):
texts.append(item)
return "".join(texts)
if isinstance(content, dict):
if content.get("type") == "text" and "text" in content:
return content["text"]
if "text" in content:
return content["text"]
return ""
if isinstance(content, str):
return content
return ""


async def build_agent(
agent: Agent, agent_data: AgentData, custom_skills: list[BaseTool] = []
) -> CompiledStateGraph:
Expand Down Expand Up @@ -149,8 +172,8 @@ async def select_model(
if llm_model.info.provider == LLMProvider.OPENAI:
tools.append({"type": "web_search"})
private_tools.append({"type": "web_search"})
if agent.model.startswith("gpt-5-"):
llm_params["reasoning_effort"] = "low"
if llm_model.info.model_name == "gpt-5-mini":
llm_params["reasoning_effort"] = "medium"
if llm_model.info.provider == LLMProvider.XAI:
llm_params["search_parameters"] = {"mode": "auto"}
# TODO: else use a search skill
Expand Down Expand Up @@ -431,31 +454,30 @@ async def stream_agent_raw(

# super mode
recursion_limit = 30
if re.search(r"\b@super\b", input_message):
if re.search(r"@super\b", input_message) or user_message.super_mode:
recursion_limit = 300
# Remove @super from the message
input_message = re.sub(r"\b@super\b", "", input_message).strip()
input_message = re.sub(r"@super\b", "", input_message).strip()

# llm native search
search = False
if re.search(r"\b@search\b", input_message) or re.search(
r"\b@web\b", input_message
):
search = user_message.search_mode if user_message.search_mode is not None else False
if re.search(r"@search\b", input_message) or re.search(r"@web\b", input_message):
search = True
if model.supports_search:
input_message = re.sub(
r"\b@search\b",
r"@search\b",
"(You have native search tool, you can use it to get more recent information)",
input_message,
).strip()
input_message = re.sub(
r"\b@web\b",
r"@web\b",
"(You have native search tool, you can use it to get more recent information)",
input_message,
).strip()
else:
input_message = re.sub(r"\b@search\b", "", input_message).strip()
input_message = re.sub(r"\b@web\b", "", input_message).strip()
search = False
input_message = re.sub(r"@search\b", "", input_message).strip()
input_message = re.sub(r"@web\b", "", input_message).strip()

# content to llm
messages = [
Expand Down Expand Up @@ -526,16 +548,7 @@ def get_agent() -> Agent:
# tool calls, save for later use, if it is deleted by post_model_hook, will not be used.
cached_tool_step = msg
if hasattr(msg, "content") and msg.content:
content = msg.content
if isinstance(msg.content, list):
# in new version, content item maybe a list
content = msg.content[0]
if isinstance(content, dict):
if "text" in content:
content = content["text"]
else:
content = str(content)
logger.error(f"unexpected content type: {content}")
content = _extract_text_content(msg.content)
# agent message
chat_message_create = ChatMessageCreate(
id=str(XID()),
Expand Down
2 changes: 1 addition & 1 deletion intentkit/core/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ async def explain_prompt(message: str) -> str:
str: The processed message with @skill patterns replaced
"""
# Pattern to match @skill:category:config_name with word boundaries
pattern = r"\b@skill:([^:]+):([^\s]+)\b"
pattern = r"@skill:([^:]+):([^\s]+)\b"

async def replace_skill_pattern(match):
category = match.group(1)
Expand Down
Loading
Loading