euriai 0.4__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- euriai/__init__.py +10 -10
- euriai/autogen.py +511 -0
- euriai/crewai.py +211 -0
- euriai/langchain.py +864 -0
- euriai/langgraph.py +1012 -0
- euriai/llamaindex.py +798 -0
- euriai/n8n.py +102 -0
- euriai/smolagents.py +819 -0
- {euriai-0.4.dist-info → euriai-1.0.0.dist-info}/METADATA +1 -1
- euriai-1.0.0.dist-info/RECORD +18 -0
- euriai/euri_autogen.py +0 -74
- euriai/euri_crewai.py +0 -92
- euriai/euri_langgraph.py +0 -64
- euriai/euri_llamaindex.py +0 -58
- euriai/euri_n8n.py +0 -30
- euriai/euri_smolagents.py +0 -44
- euriai/langchain_embed.py +0 -17
- euriai/langchain_llm.py +0 -29
- euriai-0.4.dist-info/RECORD +0 -19
- {euriai-0.4.dist-info → euriai-1.0.0.dist-info}/WHEEL +0 -0
- {euriai-0.4.dist-info → euriai-1.0.0.dist-info}/entry_points.txt +0 -0
- {euriai-0.4.dist-info → euriai-1.0.0.dist-info}/top_level.txt +0 -0
euriai/smolagents.py
ADDED
@@ -0,0 +1,819 @@
|
|
1
|
+
import asyncio
|
2
|
+
import json
|
3
|
+
import logging
|
4
|
+
import time
|
5
|
+
from dataclasses import dataclass
|
6
|
+
from enum import Enum
|
7
|
+
from typing import Any, Callable, Dict, List, Optional, Union, AsyncGenerator
|
8
|
+
from datetime import datetime
|
9
|
+
import uuid
|
10
|
+
|
11
|
+
try:
|
12
|
+
from smolagents import CodeAgent, HfApiModel, tool
|
13
|
+
except ImportError:
|
14
|
+
CodeAgent = HfApiModel = tool = None
|
15
|
+
|
16
|
+
from .client import EuriaiClient
|
17
|
+
|
18
|
+
|
19
|
+
class AgentType(Enum):
|
20
|
+
"""Pre-defined agent types for different use cases."""
|
21
|
+
CODER = "coder"
|
22
|
+
RESEARCHER = "researcher"
|
23
|
+
ANALYST = "analyst"
|
24
|
+
CREATIVE = "creative"
|
25
|
+
ASSISTANT = "assistant"
|
26
|
+
PROBLEM_SOLVER = "problem_solver"
|
27
|
+
MULTI_TOOL = "multi_tool"
|
28
|
+
SPECIALIST = "specialist"
|
29
|
+
|
30
|
+
|
31
|
+
@dataclass
|
32
|
+
class AgentConfig:
|
33
|
+
"""Configuration for agent behavior and capabilities."""
|
34
|
+
name: str
|
35
|
+
description: str
|
36
|
+
model: str = "gpt-4o"
|
37
|
+
temperature: float = 0.7
|
38
|
+
max_iterations: int = 10
|
39
|
+
timeout: int = 300
|
40
|
+
enable_memory: bool = True
|
41
|
+
enable_streaming: bool = False
|
42
|
+
error_recovery: bool = True
|
43
|
+
log_level: str = "INFO"
|
44
|
+
|
45
|
+
|
46
|
+
@dataclass
|
47
|
+
class TaskResult:
|
48
|
+
"""Result of an agent task execution."""
|
49
|
+
agent_id: str
|
50
|
+
task_id: str
|
51
|
+
task: str
|
52
|
+
result: Any
|
53
|
+
success: bool
|
54
|
+
execution_time: float
|
55
|
+
iterations: int
|
56
|
+
error_message: Optional[str] = None
|
57
|
+
usage_stats: Optional[Dict[str, Any]] = None
|
58
|
+
timestamp: datetime = None
|
59
|
+
|
60
|
+
def __post_init__(self):
|
61
|
+
if self.timestamp is None:
|
62
|
+
self.timestamp = datetime.now()
|
63
|
+
|
64
|
+
|
65
|
+
@dataclass
|
66
|
+
class AgentMemory:
|
67
|
+
"""Memory management for agent interactions."""
|
68
|
+
agent_id: str
|
69
|
+
memories: List[Dict[str, Any]]
|
70
|
+
max_memories: int = 100
|
71
|
+
|
72
|
+
def add_memory(self, memory: Dict[str, Any]):
|
73
|
+
"""Add a memory entry."""
|
74
|
+
self.memories.append(memory)
|
75
|
+
if len(self.memories) > self.max_memories:
|
76
|
+
self.memories.pop(0)
|
77
|
+
|
78
|
+
def get_recent_memories(self, count: int = 10) -> List[Dict[str, Any]]:
|
79
|
+
"""Get recent memories."""
|
80
|
+
return self.memories[-count:]
|
81
|
+
|
82
|
+
def clear_memories(self):
|
83
|
+
"""Clear all memories."""
|
84
|
+
self.memories.clear()
|
85
|
+
|
86
|
+
|
87
|
+
class EuriaiTool:
|
88
|
+
"""Enhanced tool wrapper for Euri API integration."""
|
89
|
+
|
90
|
+
def __init__(self, client: EuriaiClient, name: str, description: str,
|
91
|
+
function: Callable, model: str = "gpt-4o"):
|
92
|
+
self.client = client
|
93
|
+
self.name = name
|
94
|
+
self.description = description
|
95
|
+
self.function = function
|
96
|
+
self.model = model
|
97
|
+
self.usage_count = 0
|
98
|
+
self.total_time = 0.0
|
99
|
+
|
100
|
+
def __call__(self, *args, **kwargs):
|
101
|
+
"""Execute the tool with AI enhancement."""
|
102
|
+
start_time = time.time()
|
103
|
+
try:
|
104
|
+
# Check if tool needs AI assistance
|
105
|
+
if hasattr(self.function, '_needs_ai') and self.function._needs_ai:
|
106
|
+
# Enhance tool execution with AI
|
107
|
+
enhanced_result = self._enhance_with_ai(*args, **kwargs)
|
108
|
+
result = enhanced_result
|
109
|
+
else:
|
110
|
+
result = self.function(*args, **kwargs)
|
111
|
+
|
112
|
+
execution_time = time.time() - start_time
|
113
|
+
self.usage_count += 1
|
114
|
+
self.total_time += execution_time
|
115
|
+
|
116
|
+
return result
|
117
|
+
except Exception as e:
|
118
|
+
execution_time = time.time() - start_time
|
119
|
+
self.total_time += execution_time
|
120
|
+
raise e
|
121
|
+
|
122
|
+
def _enhance_with_ai(self, *args, **kwargs):
|
123
|
+
"""Enhance tool execution with AI assistance."""
|
124
|
+
# Create AI prompt for tool enhancement
|
125
|
+
prompt = f"""
|
126
|
+
You are helping execute a tool called '{self.name}' with description: {self.description}
|
127
|
+
|
128
|
+
Tool arguments: {args}
|
129
|
+
Tool keyword arguments: {kwargs}
|
130
|
+
|
131
|
+
Please provide intelligent assistance for this tool execution.
|
132
|
+
"""
|
133
|
+
|
134
|
+
response = self.client.chat.completions.create(
|
135
|
+
model=self.model,
|
136
|
+
messages=[{"role": "user", "content": prompt}],
|
137
|
+
temperature=0.5
|
138
|
+
)
|
139
|
+
|
140
|
+
ai_result = response.choices[0].message.content
|
141
|
+
|
142
|
+
# Combine AI result with tool function
|
143
|
+
original_result = self.function(*args, **kwargs)
|
144
|
+
|
145
|
+
return {
|
146
|
+
"original_result": original_result,
|
147
|
+
"ai_enhancement": ai_result,
|
148
|
+
"combined_result": f"{original_result}\n\nAI Enhancement: {ai_result}"
|
149
|
+
}
|
150
|
+
|
151
|
+
def get_stats(self) -> Dict[str, Any]:
|
152
|
+
"""Get tool usage statistics."""
|
153
|
+
return {
|
154
|
+
"name": self.name,
|
155
|
+
"usage_count": self.usage_count,
|
156
|
+
"total_time": self.total_time,
|
157
|
+
"average_time": self.total_time / max(self.usage_count, 1)
|
158
|
+
}
|
159
|
+
|
160
|
+
|
161
|
+
class EuriaiSmolAgent:
|
162
|
+
"""Enhanced SmolAgents integration with Euri API."""
|
163
|
+
|
164
|
+
def __init__(self,
|
165
|
+
api_key: str,
|
166
|
+
config: Optional[AgentConfig] = None,
|
167
|
+
tools: Optional[List[Callable]] = None):
|
168
|
+
"""
|
169
|
+
Initialize enhanced SmolAgent with Euri API integration.
|
170
|
+
|
171
|
+
Args:
|
172
|
+
api_key: Euri API key
|
173
|
+
config: Agent configuration
|
174
|
+
tools: List of tool functions
|
175
|
+
"""
|
176
|
+
if CodeAgent is None:
|
177
|
+
raise ImportError("SmolAgents is not installed. Please install with `pip install smolagents`.")
|
178
|
+
|
179
|
+
self.client = EuriaiClient(api_key=api_key)
|
180
|
+
self.config = config or AgentConfig(
|
181
|
+
name="Default Agent",
|
182
|
+
description="A general-purpose AI agent"
|
183
|
+
)
|
184
|
+
self.agent_id = str(uuid.uuid4())
|
185
|
+
|
186
|
+
# Initialize components
|
187
|
+
self.tools = {}
|
188
|
+
self.memory = AgentMemory(agent_id=self.agent_id, memories=[])
|
189
|
+
self.task_history = []
|
190
|
+
self.usage_stats = {
|
191
|
+
"total_tasks": 0,
|
192
|
+
"successful_tasks": 0,
|
193
|
+
"total_time": 0.0,
|
194
|
+
"api_calls": 0
|
195
|
+
}
|
196
|
+
|
197
|
+
# Setup logging
|
198
|
+
logging.basicConfig(level=getattr(logging, self.config.log_level))
|
199
|
+
self.logger = logging.getLogger(f"EuriaiSmolAgent-{self.agent_id}")
|
200
|
+
|
201
|
+
# Initialize SmolAgents
|
202
|
+
self.model = self._create_euri_model()
|
203
|
+
self.agent = CodeAgent(tools=list(self.tools.values()), model=self.model)
|
204
|
+
|
205
|
+
# Add initial tools
|
206
|
+
if tools:
|
207
|
+
for tool_fn in tools:
|
208
|
+
self.add_tool(tool_fn)
|
209
|
+
|
210
|
+
def _create_euri_model(self):
|
211
|
+
"""Create a model interface for SmolAgents using Euri API."""
|
212
|
+
class EuriModel:
|
213
|
+
def __init__(self, client, config):
|
214
|
+
self.client = client
|
215
|
+
self.config = config
|
216
|
+
|
217
|
+
def __call__(self, messages, **kwargs):
|
218
|
+
"""Make API call using Euri client."""
|
219
|
+
try:
|
220
|
+
response = self.client.chat.completions.create(
|
221
|
+
model=self.config.model,
|
222
|
+
messages=messages,
|
223
|
+
temperature=self.config.temperature,
|
224
|
+
**kwargs
|
225
|
+
)
|
226
|
+
return response.choices[0].message.content
|
227
|
+
except Exception as e:
|
228
|
+
logging.error(f"Error in Euri API call: {e}")
|
229
|
+
return f"Error: {str(e)}"
|
230
|
+
|
231
|
+
return EuriModel(self.client, self.config)
|
232
|
+
|
233
|
+
def add_tool(self, tool_fn: Callable, name: Optional[str] = None,
|
234
|
+
description: Optional[str] = None, model: Optional[str] = None) -> None:
|
235
|
+
"""Add an enhanced tool to the agent."""
|
236
|
+
tool_name = name or getattr(tool_fn, '__name__', 'unnamed_tool')
|
237
|
+
tool_description = description or getattr(tool_fn, '__doc__', 'No description provided')
|
238
|
+
tool_model = model or self.config.model
|
239
|
+
|
240
|
+
enhanced_tool = EuriaiTool(
|
241
|
+
client=self.client,
|
242
|
+
name=tool_name,
|
243
|
+
description=tool_description,
|
244
|
+
function=tool_fn,
|
245
|
+
model=tool_model
|
246
|
+
)
|
247
|
+
|
248
|
+
self.tools[tool_name] = enhanced_tool
|
249
|
+
|
250
|
+
# Update SmolAgent with new tools
|
251
|
+
self.agent = CodeAgent(tools=list(self.tools.values()), model=self.model)
|
252
|
+
|
253
|
+
self.logger.info(f"Added tool: {tool_name}")
|
254
|
+
|
255
|
+
def remove_tool(self, tool_name: str) -> None:
|
256
|
+
"""Remove a tool from the agent."""
|
257
|
+
if tool_name in self.tools:
|
258
|
+
del self.tools[tool_name]
|
259
|
+
self.agent = CodeAgent(tools=list(self.tools.values()), model=self.model)
|
260
|
+
self.logger.info(f"Removed tool: {tool_name}")
|
261
|
+
|
262
|
+
def run(self, task: str, **kwargs) -> TaskResult:
|
263
|
+
"""
|
264
|
+
Run a task with enhanced features.
|
265
|
+
|
266
|
+
Args:
|
267
|
+
task: Task description
|
268
|
+
**kwargs: Additional parameters
|
269
|
+
|
270
|
+
Returns:
|
271
|
+
TaskResult with execution details
|
272
|
+
"""
|
273
|
+
task_id = str(uuid.uuid4())
|
274
|
+
start_time = time.time()
|
275
|
+
|
276
|
+
self.logger.info(f"Starting task {task_id}: {task}")
|
277
|
+
|
278
|
+
try:
|
279
|
+
# Add task to memory
|
280
|
+
if self.config.enable_memory:
|
281
|
+
self.memory.add_memory({
|
282
|
+
"type": "task_start",
|
283
|
+
"task_id": task_id,
|
284
|
+
"task": task,
|
285
|
+
"timestamp": datetime.now()
|
286
|
+
})
|
287
|
+
|
288
|
+
# Execute with SmolAgents
|
289
|
+
result = self.agent.run(task, **kwargs)
|
290
|
+
|
291
|
+
execution_time = time.time() - start_time
|
292
|
+
|
293
|
+
# Create result object
|
294
|
+
task_result = TaskResult(
|
295
|
+
agent_id=self.agent_id,
|
296
|
+
task_id=task_id,
|
297
|
+
task=task,
|
298
|
+
result=result,
|
299
|
+
success=True,
|
300
|
+
execution_time=execution_time,
|
301
|
+
iterations=1, # SmolAgents doesn't provide iteration count
|
302
|
+
usage_stats=self._get_usage_stats()
|
303
|
+
)
|
304
|
+
|
305
|
+
# Update statistics
|
306
|
+
self.usage_stats["total_tasks"] += 1
|
307
|
+
self.usage_stats["successful_tasks"] += 1
|
308
|
+
self.usage_stats["total_time"] += execution_time
|
309
|
+
self.usage_stats["api_calls"] += 1
|
310
|
+
|
311
|
+
# Add to history
|
312
|
+
self.task_history.append(task_result)
|
313
|
+
|
314
|
+
# Add to memory
|
315
|
+
if self.config.enable_memory:
|
316
|
+
self.memory.add_memory({
|
317
|
+
"type": "task_complete",
|
318
|
+
"task_id": task_id,
|
319
|
+
"result": result,
|
320
|
+
"success": True,
|
321
|
+
"timestamp": datetime.now()
|
322
|
+
})
|
323
|
+
|
324
|
+
self.logger.info(f"Task {task_id} completed successfully")
|
325
|
+
|
326
|
+
return task_result
|
327
|
+
|
328
|
+
except Exception as e:
|
329
|
+
execution_time = time.time() - start_time
|
330
|
+
|
331
|
+
# Handle errors
|
332
|
+
error_message = str(e)
|
333
|
+
|
334
|
+
if self.config.error_recovery:
|
335
|
+
error_message = self._handle_error(e, task, task_id)
|
336
|
+
|
337
|
+
task_result = TaskResult(
|
338
|
+
agent_id=self.agent_id,
|
339
|
+
task_id=task_id,
|
340
|
+
task=task,
|
341
|
+
result=None,
|
342
|
+
success=False,
|
343
|
+
execution_time=execution_time,
|
344
|
+
iterations=1,
|
345
|
+
error_message=error_message
|
346
|
+
)
|
347
|
+
|
348
|
+
# Update statistics
|
349
|
+
self.usage_stats["total_tasks"] += 1
|
350
|
+
self.usage_stats["total_time"] += execution_time
|
351
|
+
|
352
|
+
# Add to history
|
353
|
+
self.task_history.append(task_result)
|
354
|
+
|
355
|
+
# Add to memory
|
356
|
+
if self.config.enable_memory:
|
357
|
+
self.memory.add_memory({
|
358
|
+
"type": "task_error",
|
359
|
+
"task_id": task_id,
|
360
|
+
"error": error_message,
|
361
|
+
"timestamp": datetime.now()
|
362
|
+
})
|
363
|
+
|
364
|
+
self.logger.error(f"Task {task_id} failed: {error_message}")
|
365
|
+
|
366
|
+
return task_result
|
367
|
+
|
368
|
+
async def run_async(self, task: str, **kwargs) -> TaskResult:
|
369
|
+
"""Run a task asynchronously."""
|
370
|
+
return await asyncio.get_event_loop().run_in_executor(
|
371
|
+
None, self.run, task, **kwargs
|
372
|
+
)
|
373
|
+
|
374
|
+
async def run_streaming(self, task: str, **kwargs) -> AsyncGenerator[str, None]:
|
375
|
+
"""Run a task with streaming output."""
|
376
|
+
if not self.config.enable_streaming:
|
377
|
+
raise ValueError("Streaming is not enabled for this agent")
|
378
|
+
|
379
|
+
# Note: SmolAgents doesn't natively support streaming
|
380
|
+
# This is a simulated streaming implementation
|
381
|
+
task_id = str(uuid.uuid4())
|
382
|
+
|
383
|
+
yield f"[TASK_START] {task_id}: {task}"
|
384
|
+
|
385
|
+
try:
|
386
|
+
result = await self.run_async(task, **kwargs)
|
387
|
+
|
388
|
+
# Simulate streaming by yielding chunks
|
389
|
+
result_str = str(result.result)
|
390
|
+
chunk_size = 50
|
391
|
+
|
392
|
+
for i in range(0, len(result_str), chunk_size):
|
393
|
+
chunk = result_str[i:i+chunk_size]
|
394
|
+
yield chunk
|
395
|
+
await asyncio.sleep(0.1) # Simulate processing time
|
396
|
+
|
397
|
+
yield f"\n[TASK_COMPLETE] {task_id}: Success"
|
398
|
+
|
399
|
+
except Exception as e:
|
400
|
+
yield f"\n[TASK_ERROR] {task_id}: {str(e)}"
|
401
|
+
|
402
|
+
def _handle_error(self, error: Exception, task: str, task_id: str) -> str:
|
403
|
+
"""Handle errors with recovery attempts."""
|
404
|
+
self.logger.warning(f"Error in task {task_id}: {error}")
|
405
|
+
|
406
|
+
try:
|
407
|
+
# Try to get AI assistance for error recovery
|
408
|
+
recovery_prompt = f"""
|
409
|
+
An error occurred while executing this task: {task}
|
410
|
+
|
411
|
+
Error: {str(error)}
|
412
|
+
|
413
|
+
Please provide suggestions for fixing this error or an alternative approach.
|
414
|
+
"""
|
415
|
+
|
416
|
+
response = self.client.chat.completions.create(
|
417
|
+
model=self.config.model,
|
418
|
+
messages=[{"role": "user", "content": recovery_prompt}],
|
419
|
+
temperature=0.3
|
420
|
+
)
|
421
|
+
|
422
|
+
recovery_suggestion = response.choices[0].message.content
|
423
|
+
|
424
|
+
return f"Original error: {str(error)}\n\nRecovery suggestion: {recovery_suggestion}"
|
425
|
+
|
426
|
+
except Exception as recovery_error:
|
427
|
+
return f"Original error: {str(error)}\nRecovery attempt failed: {str(recovery_error)}"
|
428
|
+
|
429
|
+
def get_tool_stats(self) -> Dict[str, Any]:
|
430
|
+
"""Get statistics for all tools."""
|
431
|
+
return {tool_name: tool.get_stats() for tool_name, tool in self.tools.items()}
|
432
|
+
|
433
|
+
def get_memory_summary(self) -> Dict[str, Any]:
|
434
|
+
"""Get a summary of agent memory."""
|
435
|
+
return {
|
436
|
+
"agent_id": self.agent_id,
|
437
|
+
"total_memories": len(self.memory.memories),
|
438
|
+
"recent_memories": self.memory.get_recent_memories(5)
|
439
|
+
}
|
440
|
+
|
441
|
+
def get_performance_metrics(self) -> Dict[str, Any]:
|
442
|
+
"""Get comprehensive performance metrics."""
|
443
|
+
return {
|
444
|
+
"agent_id": self.agent_id,
|
445
|
+
"config": {
|
446
|
+
"name": self.config.name,
|
447
|
+
"model": self.config.model,
|
448
|
+
"temperature": self.config.temperature
|
449
|
+
},
|
450
|
+
"usage_stats": self.usage_stats,
|
451
|
+
"tool_stats": self.get_tool_stats(),
|
452
|
+
"task_history_count": len(self.task_history),
|
453
|
+
"memory_stats": {
|
454
|
+
"total_memories": len(self.memory.memories),
|
455
|
+
"max_memories": self.memory.max_memories
|
456
|
+
},
|
457
|
+
"success_rate": (
|
458
|
+
self.usage_stats["successful_tasks"] / max(self.usage_stats["total_tasks"], 1)
|
459
|
+
) * 100,
|
460
|
+
"average_task_time": (
|
461
|
+
self.usage_stats["total_time"] / max(self.usage_stats["total_tasks"], 1)
|
462
|
+
)
|
463
|
+
}
|
464
|
+
|
465
|
+
def _get_usage_stats(self) -> Dict[str, Any]:
|
466
|
+
"""Get current usage statistics."""
|
467
|
+
return self.usage_stats.copy()
|
468
|
+
|
469
|
+
def export_history(self, format: str = "json") -> str:
|
470
|
+
"""Export task history in specified format."""
|
471
|
+
if format.lower() == "json":
|
472
|
+
return json.dumps([
|
473
|
+
{
|
474
|
+
"task_id": task.task_id,
|
475
|
+
"task": task.task,
|
476
|
+
"result": str(task.result),
|
477
|
+
"success": task.success,
|
478
|
+
"execution_time": task.execution_time,
|
479
|
+
"timestamp": task.timestamp.isoformat()
|
480
|
+
}
|
481
|
+
for task in self.task_history
|
482
|
+
], indent=2)
|
483
|
+
else:
|
484
|
+
raise ValueError(f"Unsupported format: {format}")
|
485
|
+
|
486
|
+
def clear_history(self) -> None:
|
487
|
+
"""Clear task history and reset statistics."""
|
488
|
+
self.task_history.clear()
|
489
|
+
self.usage_stats = {
|
490
|
+
"total_tasks": 0,
|
491
|
+
"successful_tasks": 0,
|
492
|
+
"total_time": 0.0,
|
493
|
+
"api_calls": 0
|
494
|
+
}
|
495
|
+
self.memory.clear_memories()
|
496
|
+
self.logger.info("History and statistics cleared")
|
497
|
+
|
498
|
+
def get_agent_info(self) -> Dict[str, Any]:
|
499
|
+
"""Get comprehensive agent information."""
|
500
|
+
return {
|
501
|
+
"agent_id": self.agent_id,
|
502
|
+
"config": {
|
503
|
+
"name": self.config.name,
|
504
|
+
"description": self.config.description,
|
505
|
+
"model": self.config.model,
|
506
|
+
"temperature": self.config.temperature,
|
507
|
+
"max_iterations": self.config.max_iterations,
|
508
|
+
"timeout": self.config.timeout,
|
509
|
+
"enable_memory": self.config.enable_memory,
|
510
|
+
"enable_streaming": self.config.enable_streaming,
|
511
|
+
"error_recovery": self.config.error_recovery
|
512
|
+
},
|
513
|
+
"tools": list(self.tools.keys()),
|
514
|
+
"performance": self.get_performance_metrics()
|
515
|
+
}
|
516
|
+
|
517
|
+
|
518
|
+
class EuriaiAgentBuilder:
|
519
|
+
"""Builder for creating specialized agents with pre-configured patterns."""
|
520
|
+
|
521
|
+
def __init__(self, api_key: str):
|
522
|
+
self.api_key = api_key
|
523
|
+
self.client = EuriaiClient(api_key=api_key)
|
524
|
+
|
525
|
+
def create_coder_agent(self,
|
526
|
+
name: str = "Coder Agent",
|
527
|
+
model: str = "gpt-4o",
|
528
|
+
temperature: float = 0.3) -> EuriaiSmolAgent:
|
529
|
+
"""Create a specialized coding agent."""
|
530
|
+
config = AgentConfig(
|
531
|
+
name=name,
|
532
|
+
description="A specialized agent for coding tasks",
|
533
|
+
model=model,
|
534
|
+
temperature=temperature,
|
535
|
+
max_iterations=15,
|
536
|
+
enable_memory=True,
|
537
|
+
error_recovery=True
|
538
|
+
)
|
539
|
+
|
540
|
+
agent = EuriaiSmolAgent(self.api_key, config)
|
541
|
+
|
542
|
+
# Add coding-specific tools
|
543
|
+
@tool
|
544
|
+
def analyze_code(code: str) -> str:
|
545
|
+
"""Analyze code for potential improvements."""
|
546
|
+
prompt = f"""
|
547
|
+
Analyze this code for potential improvements, bugs, and best practices:
|
548
|
+
|
549
|
+
{code}
|
550
|
+
|
551
|
+
Provide specific suggestions for improvement.
|
552
|
+
"""
|
553
|
+
|
554
|
+
response = agent.client.chat.completions.create(
|
555
|
+
model=model,
|
556
|
+
messages=[{"role": "user", "content": prompt}],
|
557
|
+
temperature=0.3
|
558
|
+
)
|
559
|
+
|
560
|
+
return response.choices[0].message.content
|
561
|
+
|
562
|
+
@tool
|
563
|
+
def debug_code(code: str, error: str) -> str:
|
564
|
+
"""Debug code with error information."""
|
565
|
+
prompt = f"""
|
566
|
+
Debug this code that's producing an error:
|
567
|
+
|
568
|
+
Code: {code}
|
569
|
+
Error: {error}
|
570
|
+
|
571
|
+
Provide a solution and explanation.
|
572
|
+
"""
|
573
|
+
|
574
|
+
response = agent.client.chat.completions.create(
|
575
|
+
model=model,
|
576
|
+
messages=[{"role": "user", "content": prompt}],
|
577
|
+
temperature=0.3
|
578
|
+
)
|
579
|
+
|
580
|
+
return response.choices[0].message.content
|
581
|
+
|
582
|
+
agent.add_tool(analyze_code)
|
583
|
+
agent.add_tool(debug_code)
|
584
|
+
|
585
|
+
return agent
|
586
|
+
|
587
|
+
def create_researcher_agent(self,
|
588
|
+
name: str = "Researcher Agent",
|
589
|
+
model: str = "gpt-4o",
|
590
|
+
temperature: float = 0.5) -> EuriaiSmolAgent:
|
591
|
+
"""Create a specialized research agent."""
|
592
|
+
config = AgentConfig(
|
593
|
+
name=name,
|
594
|
+
description="A specialized agent for research tasks",
|
595
|
+
model=model,
|
596
|
+
temperature=temperature,
|
597
|
+
max_iterations=20,
|
598
|
+
enable_memory=True,
|
599
|
+
error_recovery=True
|
600
|
+
)
|
601
|
+
|
602
|
+
agent = EuriaiSmolAgent(self.api_key, config)
|
603
|
+
|
604
|
+
# Add research-specific tools
|
605
|
+
@tool
|
606
|
+
def summarize_research(text: str) -> str:
|
607
|
+
"""Summarize research content."""
|
608
|
+
prompt = f"""
|
609
|
+
Summarize this research content, highlighting key findings and insights:
|
610
|
+
|
611
|
+
{text}
|
612
|
+
|
613
|
+
Provide a concise summary with main points.
|
614
|
+
"""
|
615
|
+
|
616
|
+
response = agent.client.chat.completions.create(
|
617
|
+
model=model,
|
618
|
+
messages=[{"role": "user", "content": prompt}],
|
619
|
+
temperature=0.5
|
620
|
+
)
|
621
|
+
|
622
|
+
return response.choices[0].message.content
|
623
|
+
|
624
|
+
@tool
|
625
|
+
def analyze_data(data: str) -> str:
|
626
|
+
"""Analyze data and provide insights."""
|
627
|
+
prompt = f"""
|
628
|
+
Analyze this data and provide insights:
|
629
|
+
|
630
|
+
{data}
|
631
|
+
|
632
|
+
Identify patterns, trends, and key insights.
|
633
|
+
"""
|
634
|
+
|
635
|
+
response = agent.client.chat.completions.create(
|
636
|
+
model=model,
|
637
|
+
messages=[{"role": "user", "content": prompt}],
|
638
|
+
temperature=0.5
|
639
|
+
)
|
640
|
+
|
641
|
+
return response.choices[0].message.content
|
642
|
+
|
643
|
+
agent.add_tool(summarize_research)
|
644
|
+
agent.add_tool(analyze_data)
|
645
|
+
|
646
|
+
return agent
|
647
|
+
|
648
|
+
def create_creative_agent(self,
|
649
|
+
name: str = "Creative Agent",
|
650
|
+
model: str = "gpt-4o",
|
651
|
+
temperature: float = 0.9) -> EuriaiSmolAgent:
|
652
|
+
"""Create a specialized creative agent."""
|
653
|
+
config = AgentConfig(
|
654
|
+
name=name,
|
655
|
+
description="A specialized agent for creative tasks",
|
656
|
+
model=model,
|
657
|
+
temperature=temperature,
|
658
|
+
max_iterations=12,
|
659
|
+
enable_memory=True,
|
660
|
+
error_recovery=True
|
661
|
+
)
|
662
|
+
|
663
|
+
agent = EuriaiSmolAgent(self.api_key, config)
|
664
|
+
|
665
|
+
# Add creative-specific tools
|
666
|
+
@tool
|
667
|
+
def generate_ideas(topic: str) -> str:
|
668
|
+
"""Generate creative ideas for a topic."""
|
669
|
+
prompt = f"""
|
670
|
+
Generate creative and innovative ideas for: {topic}
|
671
|
+
|
672
|
+
Provide diverse, original, and practical ideas.
|
673
|
+
"""
|
674
|
+
|
675
|
+
response = agent.client.chat.completions.create(
|
676
|
+
model=model,
|
677
|
+
messages=[{"role": "user", "content": prompt}],
|
678
|
+
temperature=0.9
|
679
|
+
)
|
680
|
+
|
681
|
+
return response.choices[0].message.content
|
682
|
+
|
683
|
+
@tool
|
684
|
+
def improve_content(content: str) -> str:
|
685
|
+
"""Improve and enhance content creatively."""
|
686
|
+
prompt = f"""
|
687
|
+
Improve this content to make it more engaging and creative:
|
688
|
+
|
689
|
+
{content}
|
690
|
+
|
691
|
+
Enhance style, flow, and impact while maintaining the core message.
|
692
|
+
"""
|
693
|
+
|
694
|
+
response = agent.client.chat.completions.create(
|
695
|
+
model=model,
|
696
|
+
messages=[{"role": "user", "content": prompt}],
|
697
|
+
temperature=0.9
|
698
|
+
)
|
699
|
+
|
700
|
+
return response.choices[0].message.content
|
701
|
+
|
702
|
+
agent.add_tool(generate_ideas)
|
703
|
+
agent.add_tool(improve_content)
|
704
|
+
|
705
|
+
return agent
|
706
|
+
|
707
|
+
def create_multi_model_agent(self,
|
708
|
+
name: str = "Multi-Model Agent",
|
709
|
+
models: List[str] = None) -> EuriaiSmolAgent:
|
710
|
+
"""Create an agent that can use multiple models."""
|
711
|
+
if models is None:
|
712
|
+
models = ["gpt-4o", "claude-3-sonnet-20240229", "gemini-pro"]
|
713
|
+
|
714
|
+
config = AgentConfig(
|
715
|
+
name=name,
|
716
|
+
description="An agent that can use multiple AI models",
|
717
|
+
model=models[0], # Default model
|
718
|
+
temperature=0.7,
|
719
|
+
max_iterations=15,
|
720
|
+
enable_memory=True,
|
721
|
+
error_recovery=True
|
722
|
+
)
|
723
|
+
|
724
|
+
agent = EuriaiSmolAgent(self.api_key, config)
|
725
|
+
|
726
|
+
# Add multi-model tools
|
727
|
+
@tool
|
728
|
+
def compare_models(prompt: str) -> str:
|
729
|
+
"""Compare responses from different models."""
|
730
|
+
results = {}
|
731
|
+
|
732
|
+
for model in models:
|
733
|
+
try:
|
734
|
+
response = agent.client.chat.completions.create(
|
735
|
+
model=model,
|
736
|
+
messages=[{"role": "user", "content": prompt}],
|
737
|
+
temperature=0.7
|
738
|
+
)
|
739
|
+
results[model] = response.choices[0].message.content
|
740
|
+
except Exception as e:
|
741
|
+
results[model] = f"Error: {str(e)}"
|
742
|
+
|
743
|
+
comparison = "Model Comparison Results:\n\n"
|
744
|
+
for model, result in results.items():
|
745
|
+
comparison += f"=== {model} ===\n{result}\n\n"
|
746
|
+
|
747
|
+
return comparison
|
748
|
+
|
749
|
+
@tool
|
750
|
+
def switch_model(new_model: str) -> str:
|
751
|
+
"""Switch the agent's default model."""
|
752
|
+
if new_model in models:
|
753
|
+
agent.config.model = new_model
|
754
|
+
return f"Switched to model: {new_model}"
|
755
|
+
else:
|
756
|
+
return f"Model {new_model} not available. Available models: {', '.join(models)}"
|
757
|
+
|
758
|
+
agent.add_tool(compare_models)
|
759
|
+
agent.add_tool(switch_model)
|
760
|
+
|
761
|
+
return agent
|
762
|
+
|
763
|
+
|
764
|
+
# Pre-defined agent patterns
|
765
|
+
def create_agent_pattern(api_key: str,
|
766
|
+
agent_type: AgentType,
|
767
|
+
name: Optional[str] = None,
|
768
|
+
**kwargs) -> EuriaiSmolAgent:
|
769
|
+
"""Create an agent using pre-defined patterns."""
|
770
|
+
builder = EuriaiAgentBuilder(api_key)
|
771
|
+
|
772
|
+
if agent_type == AgentType.CODER:
|
773
|
+
return builder.create_coder_agent(name or "Coder Agent", **kwargs)
|
774
|
+
elif agent_type == AgentType.RESEARCHER:
|
775
|
+
return builder.create_researcher_agent(name or "Researcher Agent", **kwargs)
|
776
|
+
elif agent_type == AgentType.CREATIVE:
|
777
|
+
return builder.create_creative_agent(name or "Creative Agent", **kwargs)
|
778
|
+
elif agent_type == AgentType.MULTI_TOOL:
|
779
|
+
return builder.create_multi_model_agent(name or "Multi-Model Agent", **kwargs)
|
780
|
+
else:
|
781
|
+
# Default agent
|
782
|
+
config = AgentConfig(
|
783
|
+
name=name or "General Agent",
|
784
|
+
description=f"A {agent_type.value} agent",
|
785
|
+
**kwargs
|
786
|
+
)
|
787
|
+
return EuriaiSmolAgent(api_key, config)
|
788
|
+
|
789
|
+
|
790
|
+
# Utility functions
|
791
|
+
def ai_tool(description: str, model: str = "gpt-4o"):
|
792
|
+
"""Decorator to create AI-enhanced tools."""
|
793
|
+
def decorator(func):
|
794
|
+
func._needs_ai = True
|
795
|
+
func._ai_model = model
|
796
|
+
func._ai_description = description
|
797
|
+
return func
|
798
|
+
return decorator
|
799
|
+
|
800
|
+
|
801
|
+
@ai_tool("Analyze sentiment of text")
|
802
|
+
def analyze_sentiment(text: str) -> str:
|
803
|
+
"""Analyze sentiment of text (AI-enhanced)."""
|
804
|
+
# This will be enhanced with AI in EuriaiTool
|
805
|
+
return f"Analyzing sentiment of: {text}"
|
806
|
+
|
807
|
+
|
808
|
+
@ai_tool("Translate text to another language")
|
809
|
+
def translate_text(text: str, target_language: str) -> str:
|
810
|
+
"""Translate text to another language (AI-enhanced)."""
|
811
|
+
# This will be enhanced with AI in EuriaiTool
|
812
|
+
return f"Translating '{text}' to {target_language}"
|
813
|
+
|
814
|
+
|
815
|
+
@ai_tool("Generate creative content")
|
816
|
+
def generate_content(topic: str, content_type: str = "article") -> str:
|
817
|
+
"""Generate creative content (AI-enhanced)."""
|
818
|
+
# This will be enhanced with AI in EuriaiTool
|
819
|
+
return f"Generating {content_type} about: {topic}"
|