-
Notifications
You must be signed in to change notification settings - Fork 149
Feat: Tools aop registry and tools namespace #19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
d309ba4
61a731c
93b9909
9eb37a0
5f86f3e
1c0aaf3
48c8e29
fc5b0e6
e8e939b
4732819
6c013fe
e4f4be7
c972062
02fa68c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @virrius а мы зачем так внутри агента настраиваем basicConfig логера?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Это наследие оригинальной версии и вопрос скорее к @virrius мой код на данном участке просто выполняет декомпозицию (раскладывает классы по файликам). |
||
|
|
||
| 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 "" |
| 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) | ||
EvilFreelancer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| 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)), | ||
| ) | ||
This file was deleted.
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.