Skip to content

Commit ce83d45

Browse files
committed
fix MCP asyncio error
1 parent 7c08a4a commit ce83d45

File tree

8 files changed

+22
-15
lines changed

8 files changed

+22
-15
lines changed

augmenta/agent.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ def create_structure_class(yaml_file_path: Union[str, Path]) -> Type[BaseModel]:
119119

120120
except (yaml.YAMLError, OSError) as e:
121121
raise ValueError(f"Failed to parse YAML: {e}")
122+
123+
def get_mcp_servers_context(self):
124+
"""Get the MCP servers context manager from the underlying agent.
125+
126+
Returns:
127+
Context manager for running MCP servers
128+
"""
129+
return self.agent.run_mcp_servers()
122130

123131
async def run(
124132
self,
@@ -147,12 +155,12 @@ async def run(
147155
if temperature is not None and temperature != self.temperature:
148156
model_settings = self._create_model_settings(temperature)
149157

150-
async with self.agent.run_mcp_servers():
151-
result = await self.agent.run(
152-
prompt,
153-
output_type=response_format,
154-
model_settings=model_settings
155-
)
158+
# Note: MCP servers context should be managed at a higher level now
159+
result = await self.agent.run(
160+
prompt,
161+
output_type=response_format,
162+
model_settings=model_settings
163+
)
156164

157165
# Return the appropriate result format
158166
return result.data.model_dump() if response_format else result.data

augmenta/augmenta.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ async def process_with_limit(row: Dict[str, Any]) -> ProcessingResult:
165165
progress_callback=update_progress
166166
)
167167

168-
tasks = [process_with_limit(row) for row in rows_to_process]
169-
results = await asyncio.gather(*tasks)
168+
# Run all tasks under a single MCP server context
169+
async with agent.get_mcp_servers_context():
170+
tasks = [process_with_limit(row) for row in rows_to_process]
171+
results = await asyncio.gather(*tasks)
170172

171173
# Update DataFrame with results
172174
successful_results, error_count = update_dataframe_with_results(df, results)

docs/examples/donations/README.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ output_csv: data/donations_classified.csv
6262
model:
6363
name: openai/gpt-4o-mini
6464
max_tokens: 20000
65-
query_col: DonorName
6665
search:
6766
engine: brave
6867
country: GB

docs/examples/donations/README.qmd

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ output_csv: data/donations_classified.csv
5555
model:
5656
name: openai/gpt-4o-mini
5757
max_tokens: 20000
58-
query_col: DonorName
5958
search:
6059
engine: brave
6160
country: GB

docs/examples/donations/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ agent: autonomous
44
model:
55
provider: openai
66
name: gpt-4o-mini
7-
query_col: DonorName
87
search:
98
engine: duckduckgo
109
results: 20

docs/examples/maps/config.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ agent: autonomous
44
model:
55
provider: openai
66
name: gpt-4o-mini
7-
query_col: city
87
search:
98
engine: duckduckgo
109
results: 20

docs/search.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Searching with Augmenta
22

3-
Augmenta supports several search engines out of the box. It will search for the `query_col` you specify, extract the links, and return the text from those links.
3+
Augmenta supports several search engines out of the box, with more available as [MCP servers](/docs/tools.md).
44

55
Some search engines have a rate limit, meaning they will only allow a certain number of searches in a given time period. You can configure Augmenta to respect this rate limit by setting the `rate_limit` parameter in your configuration file.
66

docs/tools.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Tools
22

3-
By default, Augmenta has access to two tools: a search engine and a tool for retrieving text from the internet.
3+
By default, Augmenta has access to three tools: a search engine, a tool for retrieving text from the internet, and a tool for attaching local files.
44

55
However, you may be interested in empowering it to do more. For example, you may want to give it access to a database, or give it the power to write code or do complex calculations.
66

@@ -34,4 +34,5 @@ Note that the Google Maps server needs a `GOOGLE_MAPS_API_KEY` environment varia
3434
GOOGLE_MAPS_API_KEY=XXXXX
3535
```
3636

37-
Augmenta will now have access to Google Maps. However, it will still have access to the default search tool, meaning it may decide to use it instead of the Google Maps server. You can explicitly tell the LLM to use the newly added tool in the prompts.
37+
Augmenta will now have access to Google Maps. However, it will still have access to the default search tool, meaning it may decide to use it instead of the Google Maps server. You can explicitly tell the LLM to use the newly added tool in the prompts.
38+

0 commit comments

Comments
 (0)