|
| 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