feat: add QR login and browser-backed web tools

This commit is contained in:
Azimkin
2026-09-14 14:19:20 +02:00
parent 3a8c198caa
commit b68e715267
19 changed files with 2740 additions and 8 deletions

View File

@@ -15,6 +15,8 @@ from micro_agents_tools import BraveSearchTools, FilesystemTools, PythonTools
from app.agent_tools import AgentToolManager, TelegramTools
from app.config import AiConfig, AiProviderConfig
from app.llm import ChatCompletionsLLM
from app.web_tools import WebPageTools
class AgentError(RuntimeError):
@@ -401,6 +403,15 @@ def _provider(config: AiConfig, invocation: AgentInvocation) -> AiProviderConfig
return config.deepseek if invocation.use_deepseek else config.glm
def _create_llm(provider: AiProviderConfig, invocation: AgentInvocation) -> Any:
llm_class = OpenAIBasedLLM if invocation.use_deepseek else ChatCompletionsLLM
return llm_class(
api_url=provider.api_url,
api_key=provider.api_key,
model=provider.model,
)
async def run_agent_turn(
client: Any,
command_message: Any,
@@ -433,11 +444,7 @@ async def run_agent_turn(
if not provider.api_key:
raise AgentError("The selected AI provider has no API key")
llm = OpenAIBasedLLM(
api_url=provider.api_url,
api_key=provider.api_key,
model=provider.model,
)
llm = _create_llm(provider, invocation)
templates = load_prompt_templates(config.prompt_dir)
context = _agent_context(command_message, account, invocation)
context["base_dir"] = config.base_dir
@@ -455,6 +462,10 @@ async def run_agent_turn(
template_context=context,
)
tools = [
*WebPageTools(
timeout_seconds=config.web_page_timeout_seconds,
max_chars=config.web_page_max_chars,
).tools(),
*BraveSearchTools(
api_key=config.brave_api_key,
timeout_seconds=config.brave_timeout_seconds,