Skip to content
Closed
4 changes: 3 additions & 1 deletion sgr_deep_research/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
from sgr_deep_research.core.models import AgentStatesEnum, ResearchContext, SearchResult, SourceData
from sgr_deep_research.core.prompts import PromptLoader
from sgr_deep_research.core.stream import OpenAIStreamingGenerator
from sgr_deep_research.core.tools import * # noqa: F403
from sgr_deep_research.core.tools_registry import ToolsRegistry
from sgr_deep_research.tools import * # noqa: F403

__all__ = [
# Agents
Expand All @@ -29,4 +30,5 @@
# Other core modules
"PromptLoader",
"OpenAIStreamingGenerator",
"ToolsRegistry",
]
4 changes: 2 additions & 2 deletions sgr_deep_research/core/agents/base_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
from sgr_deep_research.core.models import AgentStatesEnum, ResearchContext
from sgr_deep_research.core.prompts import PromptLoader
from sgr_deep_research.core.stream import OpenAIStreamingGenerator
from sgr_deep_research.core.tools import (
from sgr_deep_research.settings import get_config
from sgr_deep_research.tools import (
# Base
BaseTool,
ClarificationTool,
ReasoningTool,
system_agent_tools,
)
from sgr_deep_research.settings import get_config

logging.basicConfig(
level=logging.INFO,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@virrius а мы зачем так внутри агента настраиваем basicConfig логера?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Это наследие оригинальной версии и вопрос скорее к @virrius мой код на данном участке просто выполняет декомпозицию (раскладывает классы по файликам).

Expand Down
4 changes: 2 additions & 2 deletions sgr_deep_research/core/agents/sgr_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
from typing import Type

from sgr_deep_research.core.agents.base_agent import BaseAgent
from sgr_deep_research.core.tools import (
from sgr_deep_research.settings import get_config
from sgr_deep_research.tools import (
AgentCompletionTool,
BaseTool,
ClarificationTool,
Expand All @@ -15,7 +16,6 @@
research_agent_tools,
system_agent_tools,
)
from sgr_deep_research.settings import get_config

logging.basicConfig(
level=logging.INFO,
Expand Down
2 changes: 1 addition & 1 deletion sgr_deep_research/core/agents/sgr_auto_tools_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from typing import Literal, Type

from sgr_deep_research.core.agents.sgr_tools_agent import SGRToolCallingResearchAgent
from sgr_deep_research.core.tools import BaseTool
from sgr_deep_research.tools import BaseTool


class SGRAutoToolCallingResearchAgent(SGRToolCallingResearchAgent):
Expand Down
2 changes: 1 addition & 1 deletion sgr_deep_research/core/agents/sgr_so_tools_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
from typing import Type

from sgr_deep_research.core.agents.sgr_tools_agent import SGRToolCallingResearchAgent
from sgr_deep_research.core.tools import BaseTool, ReasoningTool
from sgr_deep_research.settings import get_config
from sgr_deep_research.tools import BaseTool, ReasoningTool

logging.basicConfig(
level=logging.INFO,
Expand Down
4 changes: 2 additions & 2 deletions sgr_deep_research/core/agents/sgr_tools_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from openai.types.chat import ChatCompletionFunctionToolParam

from sgr_deep_research.core.agents.sgr_agent import SGRResearchAgent
from sgr_deep_research.core.tools import (
from sgr_deep_research.settings import get_config
from sgr_deep_research.tools import (
AgentCompletionTool,
BaseTool,
ClarificationTool,
Expand All @@ -16,7 +17,6 @@
research_agent_tools,
system_agent_tools,
)
from sgr_deep_research.settings import get_config

logging.basicConfig(
level=logging.INFO,
Expand Down
4 changes: 2 additions & 2 deletions sgr_deep_research/core/agents/tools_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
from openai.types.chat import ChatCompletionFunctionToolParam

from sgr_deep_research.core.agents.base_agent import BaseAgent
from sgr_deep_research.core.tools import (
from sgr_deep_research.settings import get_config
from sgr_deep_research.tools import (
AgentCompletionTool,
BaseTool,
ClarificationTool,
Expand All @@ -16,7 +17,6 @@
research_agent_tools,
system_agent_tools,
)
from sgr_deep_research.settings import get_config

logging.basicConfig(
level=logging.INFO,
Expand Down
35 changes: 35 additions & 0 deletions sgr_deep_research/core/base_tool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from __future__ import annotations

from typing import TYPE_CHECKING, ClassVar

from pydantic import BaseModel

if TYPE_CHECKING:
from sgr_deep_research.core.models import ResearchContext


class BaseTool(BaseModel):
"""Base class for all tools providing interface for tool handling
capabilities."""

tool_name: ClassVar[str | None] = None
description: ClassVar[str | None] = None
is_system_tool: ClassVar[bool] = False

def __call__(self, context: ResearchContext) -> str:
"""Execute tool with given context. Result should be a string or dumped
json.

Args:
context: Research context containing state, sources, and other data

Returns:
String result of tool execution
"""
raise NotImplementedError("Execute method must be implemented by subclass")

def __init_subclass__(cls, **kwargs):
"""Automatically set tool_name and description for subclasses."""
super().__init_subclass__(**kwargs)
cls.tool_name = cls.tool_name or cls.__name__.lower()
cls.description = cls.description or cls.__doc__ or ""
42 changes: 42 additions & 0 deletions sgr_deep_research/core/next_step_tools.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from __future__ import annotations

import operator
from abc import ABC
from functools import reduce
from typing import Type, TypeVar

from pydantic import Field, create_model

from sgr_deep_research.core.base_tool import BaseTool
from sgr_deep_research.core.prompts import PromptLoader
from sgr_deep_research.tools.reasoning_tool import ReasoningTool

T = TypeVar("T", bound=BaseTool)


class NextStepToolStub(ReasoningTool, ABC):
"""SGR Core - Determines next reasoning step with adaptive planning, choosing appropriate tool.
(!) Stub class for correct autocomplete. Use NextStepToolsBuilder.
"""

function: BaseTool = Field(description=PromptLoader.get_tool_function_prompt())


class NextStepToolsBuilder:
"""SGR Core - Builder for NextStepTool with dynamic union tool function type on pydantic models level."""

@classmethod
def _create_tool_types_union(cls, tools_list: list[Type[BaseTool]]):
if len(tools_list) == 1:
return tools_list[0]

return reduce(operator.or_, tools_list)

@classmethod
def build_NextStepTools(cls, tools_list: list[Type[BaseTool]]) -> Type[NextStepToolStub]: # noqa
tool_prompt = PromptLoader.get_tool_function_prompt()
return create_model(
"NextStepTools",
__base__=NextStepToolStub,
function=(cls._create_tool_types_union(tools_list), Field(description=tool_prompt)),
)
32 changes: 0 additions & 32 deletions sgr_deep_research/core/tools/__init__.py

This file was deleted.

161 changes: 0 additions & 161 deletions sgr_deep_research/core/tools/base.py

This file was deleted.

Loading