Skip to content

Commit 30f221d

Browse files
EvilFreelancerMiXaiLL76virrius
authored
Moving API-server to Core (#121)
* add test ci\cd * #117 Deps cleanup * pytest.ini added * Tunes after linting * #120 Refactoring of API-server, main moved from DS to core * #120 sgr_deep_research folder moved to examples * #120 Relative paths in configs support added * #120 linter * #120 Tunes of relative path import logic * #120 linter fix * #120 relative imports in config * #120 tunning logging logic * #120 Relative imports of packages and fles * #120 linter * some beauty updates * Update test_agent_config_integration.py --------- Co-authored-by: MiXaiLL76 <mike.milos@yandex.ru> Co-authored-by: Lysenko Artem <lysenko.artem.g@gmail.com>
1 parent 116ad14 commit 30f221d

29 files changed

+698
-243
lines changed

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,45 @@ The library includes extensible tools for search, reasoning, and clarification,
99

1010
______________________________________________________________________
1111

12+
## Quick Start
13+
14+
### Installation
15+
16+
```bash
17+
pip install sgr-agent-core
18+
```
19+
20+
### Running Research Agents
21+
22+
The project includes example research agent configurations in the `examples/` directory. To get started with deep research agents:
23+
24+
1. Copy and configure the config file:
25+
26+
```bash
27+
cp examples/sgr_deep_research/config.yaml my_config.yaml
28+
# Edit my_config.yaml and set your API keys:
29+
# - llm.api_key: Your OpenAI API key
30+
# - search.tavily_api_key: Your Tavily API key (optional)
31+
```
32+
33+
2. Run the API server using the `sgr` utility:
34+
35+
```bash
36+
sgr --config-file examples/sgr_deep_research/config.yaml
37+
```
38+
39+
The server will start on `http://localhost:8010` with OpenAI-compatible API endpoints.
40+
41+
> **Note:** You can also run the server directly with Python:
42+
>
43+
> ```bash
44+
> python -m sgr_agent_core.server --config-file examples/sgr_deep_research/config.yaml
45+
> ```
46+
47+
For more examples and detailed usage instructions, see the [examples/](examples/) directory.
48+
49+
______________________________________________________________________
50+
1251
## Documentation
1352
1453
> **Get started quickly with our documentation:**

benchmark/benchmark_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from openai import pydantic_function_tool
22
from openai.types.chat import ChatCompletionFunctionToolParam
33

4-
from sgr_agent_core.agents import ResearchSGRToolCallingAgent
4+
from examples.sgr_deep_research.agents import ResearchSGRToolCallingAgent
55
from sgr_agent_core.tools import ExtractPageContentTool, FinalAnswerTool, ReasoningTool, WebSearchTool
66

77

examples/agents_with_disabled_reporting/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cp config.yaml my_config.yaml
3535
To run the SGR Deep Research API server with agents from this directory:
3636

3737
```bash
38-
python sgr_deep_research --config-file examples/agents_with_disabled_reporting/config.yaml
38+
sgr --config-file examples/agents_with_disabled_reporting/config.yaml
3939
```
4040

4141
### Using Python API

examples/agents_with_disabled_reporting/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ mcp:
3636
agents:
3737
# SGR Agent without reporting
3838
sgr_agent_no_reporting:
39-
base_class: "examples.agents_with_disabled_reporting.agents.ResearchSGRAgentNoReporting"
39+
base_class: "agents.ResearchSGRAgentNoReporting"
4040
llm:
4141
model: "gpt-4o-mini"
4242
temperature: 0.4
@@ -48,7 +48,7 @@ agents:
4848

4949
# Tool Calling Agent without reporting
5050
tool_calling_agent_no_reporting:
51-
base_class: "examples.agents_with_disabled_reporting.agents.ResearchToolCallingAgentNoReporting"
51+
base_class: "agents.ResearchToolCallingAgentNoReporting"
5252
llm:
5353
model: "gpt-4o-mini"
5454
temperature: 0.4
@@ -60,7 +60,7 @@ agents:
6060

6161
# SGR Tool Calling Agent without reporting
6262
sgr_tool_calling_agent_no_reporting:
63-
base_class: "examples.agents_with_disabled_reporting.agents.ResearchSGRToolCallingAgentNoReporting"
63+
base_class: "agents.ResearchSGRToolCallingAgentNoReporting"
6464
llm:
6565
model: "gpt-4o-mini"
6666
temperature: 0.4
Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# SGR Deep Research
2+
3+
Research agents configuration for SGR Agent Core. This package provides pre-configured research agents with web search, content extraction, and reporting capabilities.
4+
5+
## Description
6+
7+
SGR Deep Research contains research agent definitions and configuration files for running deep research tasks. The agents are based on the SGR Agent Core framework and include:
8+
9+
- **SGR Agent** - Schema-Guided Reasoning agent for structured research
10+
- **Tool Calling Agent** - Function calling agent for research tasks
11+
- **SGR Tool Calling Agent** - Hybrid SGR + function calling agent
12+
13+
All agents include:
14+
15+
- Web search capabilities (Tavily)
16+
- Content extraction from web pages
17+
- Report generation
18+
- Clarification requests
19+
- Plan generation and adaptation
20+
21+
## Installation
22+
23+
Make sure you have `sgr-agent-core` installed:
24+
25+
```bash
26+
pip install sgr-agent-core
27+
```
28+
29+
## Configuration
30+
31+
1. Copy `config.yaml` and fill in your API keys:
32+
33+
```bash
34+
cp config.yaml my_config.yaml
35+
```
36+
37+
2. Edit `my_config.yaml` and set:
38+
- `llm.api_key` - Your OpenAI API key
39+
- `search.tavily_api_key` - Your Tavily API key (optional, if using search)
40+
41+
## Usage
42+
43+
### Running the API Server
44+
45+
To run the SGR Agent Core API server with research agents from this configuration, use the `sgr` utility:
46+
47+
```bash
48+
sgr --config-file examples/sgr_deep_research/config.yaml
49+
```
50+
51+
> **Note:** You can also run the server directly with Python:
52+
>
53+
> ```bash
54+
> python -m sgr_agent_core.server --config-file examples/sgr_deep_research/config.yaml
55+
> ```
56+
57+
### Using Python API
58+
59+
```python
60+
import asyncio
61+
from pathlib import Path
62+
63+
from sgr_agent_core.agent_config import GlobalConfig
64+
from sgr_agent_core.agent_factory import AgentFactory
65+
from definitions import get_research_agents_definitions
66+
67+
# Load configuration
68+
config_path = Path(__file__).parent / "config.yaml"
69+
config = GlobalConfig.from_yaml(str(config_path))
70+
71+
# Add research agents
72+
config.agents.update(get_research_agents_definitions())
73+
74+
# Get agent definition
75+
agent_def = config.agents["sgr_agent"]
76+
77+
78+
# Create and run agent
79+
async def main():
80+
agent = await AgentFactory.create(agent_def, task="Research AI trends in 2024")
81+
82+
async for chunk in agent.stream():
83+
print(chunk, end="", flush=True)
84+
85+
result = await agent.execute()
86+
print(f"\n\nFinal result: {result}")
87+
88+
89+
asyncio.run(main())
90+
```
91+
92+
### Using OpenAI-compatible API
93+
94+
If you're running the SGR Agent Core API service, you can use these agents by specifying the agent name in your request:
95+
96+
```python
97+
from openai import OpenAI
98+
99+
client = OpenAI(
100+
base_url="http://localhost:8010/v1",
101+
api_key="dummy",
102+
)
103+
104+
response = client.chat.completions.create(
105+
model="sgr_tool_calling_agent", # Use agent name from config
106+
messages=[{"role": "user", "content": "Research AI trends in 2024"}],
107+
stream=True,
108+
)
109+
110+
for chunk in response:
111+
if chunk.choices[0].delta.content:
112+
print(chunk.choices[0].delta.content, end="")
113+
```
114+
115+
## Available Agents
116+
117+
### sgr_agent
118+
119+
Schema-Guided Reasoning agent that uses structured reasoning phases:
120+
121+
- Reasoning phase: Analyzes task and generates plan
122+
- Action phase: Executes tools based on reasoning
123+
124+
### tool_calling_agent
125+
126+
Function calling agent that uses OpenAI's function calling:
127+
128+
- Direct tool selection via function calls
129+
- Faster execution for simple tasks
130+
131+
### sgr_tool_calling_agent
132+
133+
Hybrid agent combining SGR reasoning with function calling:
134+
135+
- Reasoning phase for complex planning
136+
- Function calling for tool execution
137+
- Best balance of structure and flexibility
138+
139+
## Agent Configuration
140+
141+
### Relative Imports
142+
143+
The `base_class` field in agent definitions supports relative imports. When the config file is located in the same directory or subdirectory as your agent classes, you can use relative paths:
144+
145+
```yaml
146+
agents:
147+
sgr_agent:
148+
base_class: "agents.ResearchSGRAgent" # Relative to config.yaml location
149+
```
150+
151+
Instead of the full path:
152+
153+
```yaml
154+
agents:
155+
sgr_agent:
156+
base_class: "examples.sgr_deep_research.agents.ResearchSGRAgent" # Absolute path
157+
```
158+
159+
The system automatically resolves relative imports based on the location of the config.yaml file.
160+
161+
## Configuration Options
162+
163+
### LLM Settings
164+
165+
- `api_key`: OpenAI API key (required)
166+
- `base_url`: API base URL (default: "https://api.openai.com/v1")
167+
- `model`: Model name (default: "gpt-4o-mini")
168+
- `temperature`: Generation temperature (default: 0.4)
169+
- `max_tokens`: Maximum output tokens (default: 8000)
170+
- `proxy`: Optional proxy URL (socks5:// or http://)
171+
172+
### Search Settings
173+
174+
- `tavily_api_key`: Tavily API key (required for search)
175+
- `max_searches`: Maximum search operations (default: 4)
176+
- `max_results`: Maximum results per search (default: 10)
177+
- `content_limit`: Character limit per source (default: 1500)
178+
179+
### Execution Settings
180+
181+
- `max_clarifications`: Maximum clarification requests (default: 3)
182+
- `max_iterations`: Maximum agent iterations (default: 10)
183+
- `logs_dir`: Directory for execution logs (default: "logs")
184+
- `reports_dir`: Directory for research reports (default: "reports")
185+
186+
## Tools
187+
188+
All research agents include the following tools:
189+
190+
- **WebSearchTool** - Search the web using Tavily
191+
- **ExtractPageContentTool** - Extract content from web pages
192+
- **CreateReportTool** - Generate research reports
193+
- **FinalAnswerTool** - Provide final answers
194+
- **ClarificationTool** - Request clarifications from user
195+
- **GeneratePlanTool** - Generate research plans
196+
- **AdaptPlanTool** - Adapt plans based on findings
197+
- **ReasoningTool** - Structured reasoning (SGR agents only)
198+
199+
## Notes
200+
201+
- Agents automatically manage tool availability based on execution state
202+
- Reports are saved to `reports_dir` when `CreateReportTool` is used
203+
- Execution logs are saved to `logs_dir` for debugging
204+
- All agents support streaming responses via the API

0 commit comments

Comments
 (0)