Skip to content

Commit a0f6d5b

Browse files
committed
remove fixed agent
1 parent 231a470 commit a0f6d5b

File tree

8 files changed

+81
-202
lines changed

8 files changed

+81
-202
lines changed

augmenta/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"""Augmenta - Web research and data augmentation package."""
2+
3+
from .agent import AugmentaAgent
4+
5+
__all__ = ['AugmentaAgent']
Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
"""Unified agent module for Augmenta."""
2+
13
from typing import Type, Optional, Union, Any, Dict, ClassVar, Literal, List
24
from pathlib import Path
35
import yaml
46
from pydantic import BaseModel, Field, create_model
57
from pydantic_ai import Agent
6-
# from pydantic_ai.usage import UsageLimits
7-
# from pydantic_ai.mcp import MCPServerStdio
88
import logfire
9-
from ..tools.mcp import load_mcp_servers
9+
from .tools.mcp import load_mcp_servers
10+
from .tools.search_web import search_web
11+
from .tools.visit_webpages import visit_webpages
1012

1113
Agent.instrument_all()
1214

13-
class BaseAgent:
14-
"""Base class providing core LLM functionality"""
15+
class AugmentaAgent:
16+
"""Agent that provides LLM functionality with web research capabilities."""
1517

1618
TYPE_MAPPING: ClassVar[Dict[str, type]] = {
1719
'str': str, 'bool': bool, 'int': int,
@@ -25,19 +27,17 @@ def __init__(
2527
rate_limit: Optional[float] = None,
2628
max_tokens: Optional[int] = None,
2729
verbose: bool = False,
28-
tools: Optional[list] = None,
29-
mcp_servers: Optional[list] = None
30+
system_prompt: str = "You are a web research assistant. Use the provided tools to search for information and analyse web pages."
3031
):
31-
"""Initialize the base agent.
32+
"""Initialize the agent.
3233
3334
Args:
3435
model: The LLM model identifier
3536
temperature: Temperature setting for the model
3637
rate_limit: Optional rate limit between requests
3738
max_tokens: Optional maximum tokens for response
3839
verbose: Whether to enable verbose logging with logfire
39-
tools: Optional list of tool functions to register
40-
mcp_servers: Optional list of pre-configured MCP servers (overrides config)
40+
system_prompt: Default system prompt for the agent
4141
"""
4242
# Create model settings with all available parameters
4343
model_settings = {'temperature': temperature}
@@ -46,25 +46,25 @@ def __init__(
4646
if max_tokens is not None:
4747
model_settings['max_tokens'] = max_tokens
4848

49-
# Load MCP servers from config if not provided explicitly
50-
if mcp_servers is None:
51-
try:
52-
mcp_servers = load_mcp_servers()
53-
except RuntimeError:
54-
# Config not loaded yet, proceed without MCP servers
55-
mcp_servers = []
49+
# Load MCP servers from config
50+
try:
51+
mcp_servers = load_mcp_servers()
52+
except RuntimeError:
53+
# Config not loaded yet, proceed without MCP servers
54+
mcp_servers = []
5655

5756
self.agent = Agent(
5857
model,
5958
model_settings=model_settings,
60-
tools=tools or [],
59+
tools=[search_web, visit_webpages],
6160
mcp_servers=mcp_servers
6261
)
6362
self.model = model
6463
self.temperature = temperature
6564
self.rate_limit = rate_limit
6665
self.max_tokens = max_tokens
6766
self.verbose = verbose
67+
self.system_prompt = system_prompt
6868

6969
@staticmethod
7070
def create_structure_class(yaml_file_path: Union[str, Path]) -> Type[BaseModel]:
@@ -92,7 +92,7 @@ def create_structure_class(yaml_file_path: Union[str, Path]) -> Type[BaseModel]:
9292

9393
field_type = (Literal[tuple(str(opt) for opt in field_info['options'])]
9494
if 'options' in field_info
95-
else BaseAgent.TYPE_MAPPING.get(field_info.get('type', 'str'), str))
95+
else AugmentaAgent.TYPE_MAPPING.get(field_info.get('type', 'str'), str))
9696

9797
fields[field_name] = (
9898
field_type,
@@ -135,23 +135,31 @@ async def complete(
135135
# Set the system prompt
136136
self.agent.system_prompt = prompt_system
137137

138-
# Run the agent with the appropriate parameters
139-
# result = await self.agent.run(
140-
# prompt_user,
141-
# output_type=response_format,
142-
# model_settings=model_settings
143-
# # usage_limits=UsageLimits(request_limit=5)
144-
# )
145-
146138
async with self.agent.run_mcp_servers():
147139
result = await self.agent.run(
148140
prompt_user,
149141
output_type=response_format,
150142
model_settings=model_settings
151-
)
143+
)
152144

153145
# Return the appropriate result format
154146
return result.data.model_dump() if response_format else result.data
155147
except Exception as e:
156148
logfire.error(f"LLM request failed: {e}")
157149
raise RuntimeError(f"LLM request failed: {e}")
150+
151+
async def run(self, prompt: str, response_format: Optional[Type[BaseModel]] = None) -> Union[str, dict[str, Any], BaseModel]:
152+
"""Run the agent to perform web research.
153+
154+
Args:
155+
prompt: The research query or task
156+
response_format: Optional Pydantic model for structured output
157+
158+
Returns:
159+
The agent's response after researching, either as string, dict or Pydantic model
160+
"""
161+
return await self.complete(
162+
prompt_system=self.system_prompt,
163+
prompt_user=prompt,
164+
response_format=response_format
165+
)

augmenta/agents/__init__.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

augmenta/agents/autonomous_agent.py

Lines changed: 0 additions & 53 deletions
This file was deleted.

augmenta/agents/fixed_agent.py

Lines changed: 0 additions & 95 deletions
This file was deleted.

augmenta/augmenta.py

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
from dataclasses import dataclass
99

1010
from augmenta.utils.prompt_formatter import format_examples
11-
from augmenta.agents.base_agent import BaseAgent
12-
from augmenta.agents.autonomous_agent import AutonomousAgent
13-
from augmenta.agents.fixed_agent import FixedAgent
11+
from augmenta.agent import AugmentaAgent
1412
from augmenta.cache import CacheManager
1513
from augmenta.cache.process import handle_process_resumption, setup_caching, apply_cached_results
1614
from augmenta.config.read_config import load_config, get_config_values
@@ -45,6 +43,7 @@ async def process_augmenta(
4543

4644
# Initialize agent once for all processing
4745
config_values = get_config_values(config_data)
46+
4847
agent_settings = {
4948
"model": config_values["model_id"],
5049
"temperature": config_values["temperature"],
@@ -53,12 +52,11 @@ async def process_augmenta(
5352
"system_prompt": config_data["prompt"]["system"]
5453
}
5554

56-
agent_mode = config_data.get("agent", "autonomous")
57-
agent = (AutonomousAgent(**agent_settings) if agent_mode == "autonomous"
58-
else FixedAgent(**agent_settings))
55+
# Create agent instance
56+
agent = AugmentaAgent(**agent_settings)
5957

6058
# Create structure class once
61-
response_format = BaseAgent.create_structure_class(config_data["config_path"])
59+
response_format = AugmentaAgent.create_structure_class(config_data["config_path"])
6260

6361
# Load and validate input data
6462
df = pd.read_csv(config_data["input_csv"])
@@ -139,7 +137,7 @@ async def process_with_limit(row):
139137
async def process_row(
140138
row_data: Dict[str, Any],
141139
config: Dict[str, Any],
142-
agent: BaseAgent,
140+
agent: AugmentaAgent,
143141
response_format: Type,
144142
cache_manager: Optional[CacheManager] = None,
145143
process_id: Optional[str] = None,
@@ -161,11 +159,8 @@ async def process_row(
161159
if examples_text := format_examples(examples_yaml):
162160
prompt_user = f'{prompt_user}\n\n{examples_text}'
163161

164-
# Run prompt using the provided agent
165-
if isinstance(agent, FixedAgent):
166-
response = await agent.run(prompt_user, query=query, response_format=response_format)
167-
else:
168-
response = await agent.run(prompt_user, response_format=response_format)
162+
# Run prompt using the agent
163+
response = await agent.run(prompt_user, response_format=response_format)
169164

170165
# Handle caching if enabled
171166
if cache_manager and process_id:

docs/agent.md

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,37 @@
1-
# Fixed agent
1+
# Augmenta Agent
22

3-
By default, Augmenta runs in an "autonomous" mode, where it will autonomatically make decisions about what to search for, which resuults to read, and when it has enough information to make a decision.
3+
Augmenta uses a unified agent architecture that handles web research through a streamlined interface.
44

5-
You may want to switch to a "pre-determined" mode, where you can specify the search terms and the number of results to scrape. This is useful if you want to have more control over the search process, or if you want to use Augmenta in a more deterministic way.
5+
The `AugmentaAgent` class provides built-in capabilities for web search, content extraction, and LLM-based analysis.
66

7-
To start, add this to your `config.yml`:
7+
## Features
8+
9+
- Web search using various search providers
10+
- Content extraction from web pages
11+
- Integration with Model Context Protocol (MCP) servers
12+
- Structured output formatting via Pydantic models
13+
- Customizable system prompts and model parameters
14+
15+
## Usage
16+
17+
The agent is automatically configured when you run Augmenta with your configuration:
818

919
```yaml
10-
agent: fixed
20+
# Basic configuration example
21+
model: "openai/gpt-4o"
22+
temperature: 0.2
23+
max_tokens: 2048
24+
rate_limit: 10 # Optional: Requests per minute
1125
```
26+
27+
## Advanced Configuration
28+
29+
You can customize the agent's behavior through your configuration file:
30+
31+
```yaml
32+
prompt:
33+
system: "You are a research assistant specialized in analyzing company donations data. Your task is to categorize each donation and provide reasoning."
34+
user: "Analyze this donation: {{amount}} from {{donor}} to {{recipient}}. Provide category and reasoning."
35+
```
36+
37+
The agent integrates seamlessly with Augmenta's search and extraction tools to provide comprehensive research capabilities.

0 commit comments

Comments
 (0)