Psiska commited on
Commit
d723d2e
·
1 Parent(s): 1daae6b

Added two new tools translation and summarization tools

Browse files
__pycache__/crew.cpython-310.pyc ADDED
Binary file (7.18 kB). View file
 
__pycache__/utils.cpython-310.pyc ADDED
Binary file (1.94 kB). View file
 
app.py CHANGED
@@ -149,4 +149,6 @@ with gr.Blocks() as grady:
149
  with gr.Tab("Documentation"):
150
  gr.Markdown(os.environ.get("DOCUMENTATION"))
151
 
152
- grady.launch(mcp_server=True)
 
 
 
149
  with gr.Tab("Documentation"):
150
  gr.Markdown(os.environ.get("DOCUMENTATION"))
151
 
152
+ grady.launch(mcp_server=True)
153
+
154
+
config/agents.yaml CHANGED
@@ -78,6 +78,22 @@ code_execution_agent:
78
  backstory: >
79
  As an expert Python code execution assistant, you execute code to answer the question.
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  manager_agent:
82
  role: >
83
  Manager Agent
 
78
  backstory: >
79
  As an expert Python code execution assistant, you execute code to answer the question.
80
 
81
+ translation_agent:
82
+ role: >
83
+ A language translator agent that converts text from one language to another.
84
+ goal: >
85
+ Translate any given text into the requested target language.
86
+ backstory: >
87
+ An expert polyglot AI fluent in hundreds of languages.
88
+
89
+ summarization_agent:
90
+ role: >
91
+ A summarizer agent that condenses long text into clear and concise summaries.
92
+ goal: >
93
+ Summarize long articles, documents, or extracted content upon request.
94
+ backstory: >
95
+ A highly trained AI editor capable of identifying the core meaning of complex passages, documents, and technical content.
96
+
97
  manager_agent:
98
  role: >
99
  Manager Agent
config/tasks.yaml CHANGED
@@ -11,6 +11,8 @@ manager_task:
11
  - Arithmetic Agent requires a question and **two numbers to add, subtract, multiply, divide, or get the modulus**. In case there are more than two numbers, use the Code Generation Agent instead.
12
  - Code Generation Agent requires a question and **JSON data**.
13
  - Code Execution Agent requires a question and **Python file**.
 
 
14
  In case you cannot answer the question and there is not a good coworker, delegate to the Code Generation Agent.
15
  Question: {question}
16
  expected_output: >
 
11
  - Arithmetic Agent requires a question and **two numbers to add, subtract, multiply, divide, or get the modulus**. In case there are more than two numbers, use the Code Generation Agent instead.
12
  - Code Generation Agent requires a question and **JSON data**.
13
  - Code Execution Agent requires a question and **Python file**.
14
+ - Translation Agent requires a question and **a target language** (e.g. Translate this to French: 'Hello').
15
+ - Summarization Agent requires a question and **a long text to summarize** (e.g. Summarize this: 'The history of AI began in...').
16
  In case you cannot answer the question and there is not a good coworker, delegate to the Code Generation Agent.
17
  Question: {question}
18
  expected_output: >
crew.py CHANGED
@@ -150,6 +150,28 @@ class GAIACrew():
150
  tools=[AITools.code_execution_tool],
151
  verbose=True
152
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
 
154
  @agent
155
  def manager_agent(self) -> Agent:
@@ -160,7 +182,7 @@ class GAIACrew():
160
  max_iter=5,
161
  verbose=True
162
  )
163
-
164
  @task
165
  def manager_task(self) -> Task:
166
  return Task(
 
150
  tools=[AITools.code_execution_tool],
151
  verbose=True
152
  )
153
+
154
+ @agent
155
+ def translation_agent(self) -> Agent:
156
+ return Agent(
157
+ config=self.agents_config["translation_agent"],
158
+ allow_delegation=False,
159
+ llm=AGENT_MODEL,
160
+ max_iter=2,
161
+ tools=[AITools.translate_tool],
162
+ verbose=True
163
+ )
164
+
165
+ @agent
166
+ def summarization_agent(self) -> Agent:
167
+ return Agent(
168
+ config=self.agents_config["summarization_agent"],
169
+ allow_delegation=False,
170
+ llm=AGENT_MODEL,
171
+ max_iter=2,
172
+ tools=[AITools.summarize_tool],
173
+ verbose=True
174
+ )
175
 
176
  @agent
177
  def manager_agent(self) -> Agent:
 
182
  max_iter=5,
183
  verbose=True
184
  )
185
+
186
  @task
187
  def manager_task(self) -> Task:
188
  return Task(
tools/__pycache__/__init__.cpython-310.pyc ADDED
Binary file (125 Bytes). View file
 
tools/__pycache__/ai_tools.cpython-310.pyc ADDED
Binary file (10.9 kB). View file
 
tools/__pycache__/arithmetic_tools.cpython-310.pyc ADDED
Binary file (2.01 kB). View file
 
tools/ai_tools.py CHANGED
@@ -319,4 +319,53 @@ class AITools():
319
  if part.code_execution_result is not None:
320
  return part.code_execution_result.output
321
  except Exception as e:
322
- raise RuntimeError(f"Processing failed: {str(e)}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
319
  if part.code_execution_result is not None:
320
  return part.code_execution_result.output
321
  except Exception as e:
322
+ raise RuntimeError(f"Processing failed: {str(e)}")
323
+
324
+ @tool("Translation Tool")
325
+ def translate_tool(text: str, target_lang: str) -> str:
326
+ """Translate a given text into the target language.
327
+
328
+ Args:
329
+ text (str): The text to translate.
330
+ target_lang (str): The target language (e.g., 'french', 'de', 'zh').
331
+
332
+ Returns:
333
+ str: Translated text.
334
+ """
335
+ try:
336
+ client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
337
+
338
+ prompt = f"Translate this text to {target_lang}: '{text}'"
339
+
340
+ response = client.models.generate_content(
341
+ model="gemini-2.5-flash-preview-04-17",
342
+ contents=prompt
343
+ )
344
+
345
+ return response.text
346
+ except Exception as e:
347
+ raise RuntimeError(f"Translation failed: {str(e)}")
348
+
349
+ @tool("Summarization Tool")
350
+ def summarize_tool(text: str) -> str:
351
+ """Summarize the given text input.
352
+
353
+ Args:
354
+ text (str): Long content to summarize.
355
+
356
+ Returns:
357
+ str: A concise summary.
358
+ """
359
+ try:
360
+ client = genai.Client(api_key=os.environ["GEMINI_API_KEY"])
361
+
362
+ prompt = f"Summarize this content: {text}"
363
+
364
+ response = client.models.generate_content(
365
+ model="gemini-2.5-flash-preview-04-17",
366
+ contents=prompt
367
+ )
368
+
369
+ return response.text
370
+ except Exception as e:
371
+ raise RuntimeError(f"Summarization failed: {str(e)}")