cognitrix 0.2.3__tar.gz → 0.2.5__tar.gz

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.
Files changed (39) hide show
  1. cognitrix-0.2.5/PKG-INFO +163 -0
  2. cognitrix-0.2.5/README.md +110 -0
  3. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/agents/base.py +129 -65
  4. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/agents/templates.py +31 -36
  5. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/cli.py +77 -21
  6. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/config.py +2 -3
  7. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/__init__.py +3 -1
  8. cognitrix-0.2.5/cognitrix/llms/base.py +194 -0
  9. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/clarifai_llm.py +12 -8
  10. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/cohere_llm.py +27 -8
  11. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/google_llm.py +8 -17
  12. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/groq_llm.py +22 -7
  13. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/local_llm.py +6 -5
  14. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/mindsdb_llm.py +7 -4
  15. cognitrix-0.2.5/cognitrix/llms/ollama_llm.py +116 -0
  16. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/openai_llm.py +19 -17
  17. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/session.py +2 -2
  18. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/together_llm.py +5 -2
  19. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/tools/base.py +22 -1
  20. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/tools/misc.py +128 -113
  21. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/tools/python.py +1 -0
  22. cognitrix-0.2.5/cognitrix/tools/tool.py +38 -0
  23. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/transcriber.py +25 -13
  24. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/utils/__init__.py +69 -21
  25. {cognitrix-0.2.3 → cognitrix-0.2.5}/pyproject.toml +8 -5
  26. cognitrix-0.2.3/PKG-INFO +0 -127
  27. cognitrix-0.2.3/README.md +0 -77
  28. cognitrix-0.2.3/cognitrix/llms/base.py +0 -90
  29. cognitrix-0.2.3/cognitrix/tools/tool.py +0 -26
  30. {cognitrix-0.2.3 → cognitrix-0.2.5}/LICENSE +0 -0
  31. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/__init__.py +0 -0
  32. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/agents/__init__.py +0 -0
  33. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/agents/assistant.py +0 -0
  34. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/agents/core.py +0 -0
  35. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/app.py +0 -0
  36. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/llms/anthropic_llm.py +0 -0
  37. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/tasks/__init__.py +0 -0
  38. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/tasks/base.py +0 -0
  39. {cognitrix-0.2.3 → cognitrix-0.2.5}/cognitrix/tools/__init__.py +0 -0
@@ -0,0 +1,163 @@
1
+ Metadata-Version: 2.1
2
+ Name: cognitrix
3
+ Version: 0.2.5
4
+ Summary: Package for creating AI Agents using llms
5
+ Home-page: https://github.com/theonlyamos/cognitrix
6
+ License: Apache2
7
+ Keywords: cognitrix,ai,agents,ai agents,ai-agents,llms,autonomous agents
8
+ Author: theonlyamos
9
+ Author-email: theonlyamos@gmail.com
10
+ Requires-Python: >=3.12,<4.0
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: License :: OSI Approved :: Apache Software License
14
+ Classifier: License :: Other/Proprietary License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.12
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.6
21
+ Classifier: Programming Language :: Python :: 3.7
22
+ Classifier: Programming Language :: Python :: 3.8
23
+ Classifier: Programming Language :: Python :: 3.9
24
+ Classifier: Topic :: Software Development :: Build Tools
25
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
26
+ Requires-Dist: aiofiles (>=23.2.1,<24.0.0)
27
+ Requires-Dist: aiohttp (>=3.9.3,<4.0.0)
28
+ Requires-Dist: anthropic (>=0.17.0,<0.18.0)
29
+ Requires-Dist: beautifulsoup4 (>=4.12.3,<5.0.0)
30
+ Requires-Dist: clarifai (>=10.1.0,<11.0.0)
31
+ Requires-Dist: cohere (>=5.5.6,<6.0.0)
32
+ Requires-Dist: deepgram-sdk (==3.*)
33
+ Requires-Dist: flask (>=3.0.3,<4.0.0)
34
+ Requires-Dist: google-generativeai (>=0.4.0,<0.5.0)
35
+ Requires-Dist: groq (>=0.4.1,<0.5.0)
36
+ Requires-Dist: ollama (>=0.2.0,<0.3.0)
37
+ Requires-Dist: openai (>=1.12.0,<2.0.0)
38
+ Requires-Dist: pillow (>=10.2.0,<11.0.0)
39
+ Requires-Dist: pyaudio (>=0.2.14,<0.3.0)
40
+ Requires-Dist: pyautogui (>=0.9.54,<0.10.0)
41
+ Requires-Dist: pydantic (>=2.6.2,<3.0.0)
42
+ Requires-Dist: pydub (>=0.25.1,<0.26.0)
43
+ Requires-Dist: python-dotenv (>=1.0.1,<2.0.0)
44
+ Requires-Dist: requests (>=2.31.0,<3.0.0)
45
+ Requires-Dist: tavily-python (>=0.3.3,<0.4.0)
46
+ Requires-Dist: together (>=0.2.11,<0.3.0)
47
+ Requires-Dist: uuid (>=1.30,<2.0)
48
+ Requires-Dist: uvicorn (>=0.30.1,<0.31.0)
49
+ Requires-Dist: xmltodict (>=0.13.0,<0.14.0)
50
+ Project-URL: Bug Tracker, https://github.com/theonlyamos/cognitrix/issues
51
+ Project-URL: Repository, https://github.com/theonlyamos/cognitrix
52
+ Description-Content-Type: text/markdown
53
+
54
+ # Cognitrix
55
+
56
+ Cognitrix is an open-source autonomous AI agents orchestrator built in Python. It allows you to create and manage AI agents with ease and integrates seamlessly with large language models (LLMs) from various providers.
57
+
58
+ ## Features
59
+
60
+ - **Agent Creation and Management:** Create, list, and load AI agents with customizable names, tasks, and configurations.
61
+ - **LLM Integration:** Integrates with multiple LLM providers, including Anthropic (Claude), Cohere, Groq, Google, OpenAI, and Together.
62
+ - **Modular Architecture:** Easily extensible, allowing the addition of new tools, agents, and LLM integrations.
63
+ - **Conversational Interface:** Interact with AI agents through a command-line interface, providing queries and receiving responses.
64
+ - **Tool Integration:** Agents can utilize a variety of tools, including calculators, web searches, file system browsers, and more.
65
+ - **Autonomous Agent Mode:** Agents can operate autonomously, visually perceiving the screen, interacting with UI elements, and performing tasks.
66
+ - **Multimodal Support:** Handles both text and image inputs/outputs, enabling multimodal interactions.
67
+
68
+ ## Architecture
69
+
70
+ Cognitrix's architecture is designed to be highly modular and extensible:
71
+
72
+ - **Agents:** The base `Agent` class and specialized classes like `AIAssistant` for creating and managing AI agents.
73
+ - **LLMs:** A collection of classes for integrating with various LLM providers (Cohere, OpenAI, Claude, etc.).
74
+ - **Tools:** A set of tools that agents can utilize. Each tool has a `category` attribute for grouping and management.
75
+ - **Templates:** Customizable prompt templates guide the behavior and output formats of LLMs.
76
+
77
+ More tools can be added by creating new classes that inherit from the `Tool` base class and specifying a unique `category`.
78
+
79
+ ## Installation
80
+
81
+ ```bash
82
+ pip install cognitrix
83
+ ```
84
+
85
+ Alternatively, you can install directly from GitHub:
86
+
87
+ ```bash
88
+ pip install https://github.com/theonlyamos/cognitrix/archive/main.zip
89
+ ```
90
+
91
+ ## Usage
92
+
93
+ To run Cognitrix with default settings:
94
+
95
+ ```bash
96
+ cognitrix
97
+ ```
98
+
99
+ To list supported LLM providers:
100
+
101
+ ```bash
102
+ cognitrix --providers
103
+ ```
104
+
105
+ To list created agents:
106
+
107
+ ```bash
108
+ cognitrix agents
109
+ ```
110
+
111
+ To list available tools:
112
+
113
+ ```bash
114
+ cognitrix --tools
115
+ ```
116
+
117
+ To run Cognitrix with a specific provider:
118
+
119
+ ```bash
120
+ cognitrix --provider <provider_name>
121
+ ```
122
+
123
+ To run Cognitrix with a specific agent:
124
+
125
+ ```bash
126
+ cognitrix --agent <agent_name>
127
+ ```
128
+
129
+ To run Cognitrix with a category of tools:
130
+
131
+ ```bash
132
+ cognitrix --load-tools "web"
133
+ ```
134
+
135
+ To run Cognitrix with categories of tools:
136
+
137
+ ```bash
138
+ cognitrix --load-tools "web,general"
139
+ ```
140
+
141
+ To create a new agent:
142
+
143
+ ```bash
144
+ cognitrix agents --new
145
+ ```
146
+
147
+ For more options and usage details, use the help command:
148
+
149
+ ```bash
150
+ cognitrix --help
151
+ ```
152
+
153
+ ## Contributing
154
+
155
+ Cognitrix is open source and contributions are welcome! Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute.
156
+
157
+ ## License
158
+
159
+ This project is licensed under the MIT license. See [LICENSE.md](LICENSE.md) for more information.
160
+
161
+ ## Acknowledgments
162
+
163
+ Cognitrix was created by [Amos Amissah](https://github.com/theonlyamos) and is inspired by projects like AutoGPT and GPT Engineer. Special thanks to the open-source community and AI companies providing LLM APIs.
@@ -0,0 +1,110 @@
1
+ # Cognitrix
2
+
3
+ Cognitrix is an open-source autonomous AI agents orchestrator built in Python. It allows you to create and manage AI agents with ease and integrates seamlessly with large language models (LLMs) from various providers.
4
+
5
+ ## Features
6
+
7
+ - **Agent Creation and Management:** Create, list, and load AI agents with customizable names, tasks, and configurations.
8
+ - **LLM Integration:** Integrates with multiple LLM providers, including Anthropic (Claude), Cohere, Groq, Google, OpenAI, and Together.
9
+ - **Modular Architecture:** Easily extensible, allowing the addition of new tools, agents, and LLM integrations.
10
+ - **Conversational Interface:** Interact with AI agents through a command-line interface, providing queries and receiving responses.
11
+ - **Tool Integration:** Agents can utilize a variety of tools, including calculators, web searches, file system browsers, and more.
12
+ - **Autonomous Agent Mode:** Agents can operate autonomously, visually perceiving the screen, interacting with UI elements, and performing tasks.
13
+ - **Multimodal Support:** Handles both text and image inputs/outputs, enabling multimodal interactions.
14
+
15
+ ## Architecture
16
+
17
+ Cognitrix's architecture is designed to be highly modular and extensible:
18
+
19
+ - **Agents:** The base `Agent` class and specialized classes like `AIAssistant` for creating and managing AI agents.
20
+ - **LLMs:** A collection of classes for integrating with various LLM providers (Cohere, OpenAI, Claude, etc.).
21
+ - **Tools:** A set of tools that agents can utilize. Each tool has a `category` attribute for grouping and management.
22
+ - **Templates:** Customizable prompt templates guide the behavior and output formats of LLMs.
23
+
24
+ More tools can be added by creating new classes that inherit from the `Tool` base class and specifying a unique `category`.
25
+
26
+ ## Installation
27
+
28
+ ```bash
29
+ pip install cognitrix
30
+ ```
31
+
32
+ Alternatively, you can install directly from GitHub:
33
+
34
+ ```bash
35
+ pip install https://github.com/theonlyamos/cognitrix/archive/main.zip
36
+ ```
37
+
38
+ ## Usage
39
+
40
+ To run Cognitrix with default settings:
41
+
42
+ ```bash
43
+ cognitrix
44
+ ```
45
+
46
+ To list supported LLM providers:
47
+
48
+ ```bash
49
+ cognitrix --providers
50
+ ```
51
+
52
+ To list created agents:
53
+
54
+ ```bash
55
+ cognitrix agents
56
+ ```
57
+
58
+ To list available tools:
59
+
60
+ ```bash
61
+ cognitrix --tools
62
+ ```
63
+
64
+ To run Cognitrix with a specific provider:
65
+
66
+ ```bash
67
+ cognitrix --provider <provider_name>
68
+ ```
69
+
70
+ To run Cognitrix with a specific agent:
71
+
72
+ ```bash
73
+ cognitrix --agent <agent_name>
74
+ ```
75
+
76
+ To run Cognitrix with a category of tools:
77
+
78
+ ```bash
79
+ cognitrix --load-tools "web"
80
+ ```
81
+
82
+ To run Cognitrix with categories of tools:
83
+
84
+ ```bash
85
+ cognitrix --load-tools "web,general"
86
+ ```
87
+
88
+ To create a new agent:
89
+
90
+ ```bash
91
+ cognitrix agents --new
92
+ ```
93
+
94
+ For more options and usage details, use the help command:
95
+
96
+ ```bash
97
+ cognitrix --help
98
+ ```
99
+
100
+ ## Contributing
101
+
102
+ Cognitrix is open source and contributions are welcome! Please refer to [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines on how to contribute.
103
+
104
+ ## License
105
+
106
+ This project is licensed under the MIT license. See [LICENSE.md](LICENSE.md) for more information.
107
+
108
+ ## Acknowledgments
109
+
110
+ Cognitrix was created by [Amos Amissah](https://github.com/theonlyamos) and is inspired by projects like AutoGPT and GPT Engineer. Special thanks to the open-source community and AI companies providing LLM APIs.
@@ -1,19 +1,17 @@
1
1
  import inspect
2
2
  import json
3
- import sys
4
3
  import uuid
5
4
  import asyncio
6
5
  import logging
7
6
  import aiofiles
8
- from pathlib import Path
9
7
  from threading import Thread
10
- from typing import List, Optional, Self, TypeAlias, Union, Type, Any
11
- from dataclasses import dataclass
8
+ from datetime import datetime
9
+ from typing import Dict, List, Optional, Self, TypeAlias, Union, Type, Any
12
10
 
13
11
  from pydantic import BaseModel, Field
14
12
 
15
13
  from cognitrix.tasks import Task
16
- from cognitrix.llms.base import LLM
14
+ from cognitrix.llms.base import LLM, LLMResponse
17
15
  from cognitrix.tools.base import Tool
18
16
  from cognitrix.utils import extract_json, json_return_format
19
17
  from cognitrix.agents.templates import AUTONOMOUSE_AGENT_2
@@ -27,43 +25,112 @@ AgentList: TypeAlias = List['Agent']
27
25
 
28
26
  class Agent(BaseModel):
29
27
  name: str = Field(default='Agent')
28
+ """Name of the agent"""
29
+
30
30
  llm: LLM
31
+ """LLM Provider to use for the agent"""
32
+
31
33
  tools: List[Tool] = Field(default_factory=list)
34
+ """List of tools to be use by the agent"""
35
+
32
36
  prompt_template: str = Field(default=AUTONOMOUSE_AGENT_2)
37
+ """Agent's prompt template"""
38
+
33
39
  verbose: bool = Field(default=False)
40
+ """Set agent verbosity"""
41
+
34
42
  sub_agents: AgentList = Field(default_factory=list)
43
+ """List of sub agents which can be called by this agent"""
44
+
35
45
  task: Optional[Task] = None
46
+ """The task to be completed by the agent"""
47
+
36
48
  is_sub_agent: bool = Field(default=False)
49
+ """Whether this agent is a sub agent for another agent"""
50
+
37
51
  id: str = Field(default_factory=lambda: uuid.uuid4().hex)
52
+ """Unique id for the agent"""
53
+
38
54
  parent_id: Optional[str] = None
55
+ """Id of this agent's parent agent (if it's a sub agent)"""
56
+
39
57
  autostart: bool = False
58
+ """Whether the agent should start running as soon as it's created"""
40
59
 
41
60
  @property
42
61
  def available_tools(self) -> List[str]:
43
62
  return [tool.name for tool in self.tools]
63
+
64
+ def format_tools_for_llm(self):
65
+ TYPE_HINTS = {
66
+ "<class 'int'>": 'integer',
67
+ "<class 'str'>": 'string',
68
+ "<class 'float'>": 'float',
69
+ "<class 'dict'>": 'object',
70
+ "<class 'list'>": 'array',
71
+ "typing.Dict": 'object',
72
+ "typing.List": 'array',
73
+ "typing.Optional[int]": 'integer',
74
+ "typing.Optional[str]": 'integer',
75
+ "typing.Optional[float]": 'float',
76
+ }
77
+ llm_tools: list[dict[str, Any]] = []
78
+ classes = []
79
+ for tool in self.tools:
80
+ tool_parameters = tool.parameters
81
+ if not tool_parameters:
82
+ func_signatures = inspect.signature(tool.run)
83
+ tool_parameters = func_signatures.parameters
84
+
85
+ parameters = tool_parameters.keys()
86
+ tool_details = {
87
+ 'tool': tool,
88
+ 'name': tool.name,
89
+ 'description': tool.description,
90
+ 'parameters': {},
91
+ 'required': []
92
+ }
93
+
94
+ if not 'args' in parameters:
95
+ tool_details['parameters'] = {name: TYPE_HINTS.get(str(param.annotation), 'string') for name, param in tool_parameters.items()}
96
+ tool_details['required'] = [name for name, param in tool_parameters.items() if param.default is inspect._empty]
97
+
98
+ llm_tools.append(tool_details)
99
+
100
+ self.llm.format_tools(llm_tools)
44
101
 
45
102
  def format_system_prompt(self):
46
103
  tools_str = self._format_tools_string()
47
104
  subagents_str = self._format_subagents_string()
48
105
  llms_str = self._format_llms_string()
49
106
 
50
- prompt = self.prompt_template
107
+ today = (datetime.now()).strftime("%a %b %d %Y")
108
+ prompt = f"Today is {today}.\n\n"
109
+ prompt += self.prompt_template
51
110
  prompt = prompt.replace("{name}", self.name)
111
+
112
+ # if not self.llm.supports_tool_use:
52
113
  prompt = prompt.replace("{tools}", tools_str)
53
114
  prompt = prompt.replace("{subagents}", subagents_str)
115
+
116
+ # if not self.llm.supports_tool_use:
54
117
  prompt = prompt.replace("{available_tools}", json.dumps(self.available_tools))
55
118
  prompt = prompt.replace("{llms}", llms_str)
56
119
  prompt = prompt.replace("{return_format}", json_return_format)
57
120
 
58
121
  if 'json' not in prompt.lower():
59
122
  prompt += f"\n{json_return_format}"
60
-
123
+
61
124
  self.llm.system_prompt = prompt
125
+
126
+ self.format_tools_for_llm()
62
127
 
63
128
  def _format_tools_string(self) -> str:
64
129
  return "You have access to the following Tools:\n" + "\n".join([f"{tool.name}: {tool.description}" for tool in self.tools])
65
130
 
66
131
  def _format_subagents_string(self) -> str:
132
+ if not len(self.sub_agents):
133
+ return ''
67
134
  subagents_str = "Available Subagents:\n"
68
135
  subagents_str += "\n".join([f"-- {agent.name}: {agent.task.description}" for agent in self.sub_agents if agent.task])
69
136
  subagents_str += "\nYou should always use a subagent for a task if there is one specifically created for that task."
@@ -83,6 +150,7 @@ class Agent(BaseModel):
83
150
  if self.is_sub_agent:
84
151
  print("=======is sub agent===========")
85
152
  print(processed_query)
153
+
86
154
  result = processed_query['result']
87
155
  if isinstance(result, list):
88
156
  if result[0] == 'image':
@@ -115,52 +183,44 @@ class Agent(BaseModel):
115
183
  def get_tool_by_name(self, name: str) -> Optional[Tool]:
116
184
  return next((tool for tool in self.tools if tool.name.lower() == name.lower()), None)
117
185
 
118
- async def process_response(self, response: str) -> Union[dict, str]:
119
- # response = response.replace("'", '"')
120
- response = response.replace('\\n', '')
121
- response = response.replace("'", "\"")
122
- # response = response.replace('"', '\\"')
123
- response_data = extract_json(response)
124
-
125
-
186
+ async def call_tools(self, tool_calls: list) -> Union[dict, str]:
187
+
126
188
  try:
127
- if isinstance(response_data, dict):
128
- final_result_keys = ['final_answer', 'function_call_result', 'respons']
129
-
130
- if response_data['type'].replace('\\', '') in final_result_keys:
131
- return response_data['result']
132
-
133
- tool = self.get_tool_by_name(response_data['function'])
134
- if isinstance(response_data['arguments'], dict):
135
- response_data['arguments'] = list(response_data['arguments'].values())
136
-
137
- if response_data['function'].lower() == 'create agents':
138
- response_data['arguments'] = [*response_data['arguments'], self.id]
139
-
140
- if not tool:
141
- raise Exception(f"Tool {response_data['function']} not found")
142
-
143
- print(f"\nRunning tool '{tool.name.title()}' with parameters: {response_data['arguments']}")
144
-
145
- if 'sub agent' in tool.name.lower():
146
- response_data['arguments'].append(self)
189
+ if tool_calls:
190
+ tool_calls_result = []
191
+ for t in tool_calls:
192
+ tool = self.get_tool_by_name(t['name'])
147
193
 
148
- if tool.name.lower() == 'create sub agent':
149
- result = await tool.arun(*response_data['arguments'])
150
- else:
151
- result = tool.run(*response_data['arguments'])
152
-
153
- response_json = {
154
- 'type': 'function_call_result',
155
- 'result': result
194
+ if not tool:
195
+ print(f"Tool '{t['name']}' not found")
196
+ raise Exception(f"Tool '{t['name']}' not found")
197
+
198
+ print(f"\nRunning tool '{tool.name.title()}' with parameters: {t['arguments']}")
199
+
200
+ if 'sub agent' in tool.name.lower():
201
+ t['arguments']['parent'] = self
202
+
203
+ if tool.name.lower() == 'create sub agent':
204
+ result = await tool.arun(*t['arguments'])
205
+ else:
206
+ result = tool.run(**t['arguments'])
207
+
208
+ tool_calls_result.append({
209
+ 'tool_call_id': t['name'],
210
+ 'role': 'tool',
211
+ 'name': tool.name,
212
+ 'content': result
213
+ })
214
+
215
+ return {
216
+ 'type': 'tool_calls_result',
217
+ 'result': f"The results of the tool_calls are {json.dumps(tool_calls_result)}"
156
218
  }
157
-
158
- return response_json
159
219
  else:
160
220
  raise Exception('Not a json object')
161
221
  except Exception as e:
162
- # logger.exception(e)
163
- return response_data
222
+ logger.exception(e)
223
+ return str(e)
164
224
 
165
225
  def add_tool(self, tool: Tool):
166
226
  self.tools.append(tool)
@@ -206,18 +266,22 @@ class Agent(BaseModel):
206
266
  response: Any = self.llm(full_prompt)
207
267
 
208
268
  self.llm.chat_history.append(full_prompt)
209
- self.llm.chat_history.append({'role': self.name, 'type': 'text', 'message': response})
210
-
211
- if self.verbose:
212
- print(response)
213
-
214
- result: dict[Any, Any] | str = asyncio.run(self.process_response(response))
269
+
270
+ if response.text:
271
+ self.llm.chat_history.append({'role': self.name, 'type': 'text', 'message': response.text})
272
+ print(f"\n{self.name}: {response.text}")
273
+
274
+ if response.tool_calls:
275
+ result: dict[Any, Any] | str = asyncio.run(self.call_tools(response.tool_calls))
215
276
 
216
- if isinstance(result, dict) and result['type'] == 'function_call_result':
217
- query = result
277
+ if isinstance(result, dict) and result['type'] == 'tool_calls_result':
278
+ query = result
279
+ else:
280
+ print(result)
218
281
  else:
219
- print(f"\n{self.name}: {result}")
220
282
  query = input("\nUser (q to quit): ")
283
+
284
+ # query = input("\nUser (q to quit): ")
221
285
 
222
286
  self.save_session(session)
223
287
 
@@ -246,21 +310,21 @@ class Agent(BaseModel):
246
310
  if self.verbose:
247
311
  print(response)
248
312
 
249
- processsed_response: dict[Any, Any] | str = asyncio.run(self.process_response(response))
313
+ processsed_response: dict[Any, Any] | str = asyncio.run(self.call_tools(response))
250
314
 
251
- if isinstance(processsed_response, dict) and processsed_response['type'] == 'function_call_result':
315
+ if isinstance(processsed_response, dict) and processsed_response['type'] == 'tool_calls_result':
252
316
  query = processsed_response
253
317
  else:
254
- print(f"\n{self.name}: {processsed_response}")
255
318
  if isinstance(processsed_response, str):
256
319
  transcriber.text_to_speech(processsed_response)
320
+ print(f"\n{self.name}: {processsed_response}")
257
321
 
258
322
 
259
323
  def start_audio(self, **kwargs):
260
324
  transcriber = Transcriber(on_message_callback=self.handle_transcription) # Pass callback to Transcriber
261
325
  if transcriber.start_transcription():
262
326
  print("Audio transcription started.")
263
- input("\n\nPress Enter to stop recording...\n\n")
327
+ input("\n\nPress Enter to quit...\n\n")
264
328
  transcriber.stop_transcription()
265
329
  else:
266
330
  print("Failed to start audio transcription.")
@@ -285,8 +349,8 @@ class Agent(BaseModel):
285
349
  if parent.verbose:
286
350
  print(response)
287
351
 
288
- agent_result = asyncio.run(self.process_response(response))
289
- if isinstance(agent_result, dict) and agent_result['type'] == 'function_call_result':
352
+ agent_result = asyncio.run(self.call_tools(response))
353
+ if isinstance(agent_result, dict) and agent_result['type'] == 'tool_calls_result':
290
354
  query = agent_result
291
355
  else:
292
356
  print(f"\n--{self.name}: {agent_result}")
@@ -295,7 +359,7 @@ class Agent(BaseModel):
295
359
  parent_response: Any = parent.llm(parent_prompt)
296
360
  parent.llm.chat_history.append(parent_prompt)
297
361
  parent.llm.chat_history.append({'role': 'assistant', 'type': 'text', 'message': parent_response})
298
- parent_result = asyncio.run(parent.process_response(parent_response))
362
+ parent_result = asyncio.run(parent.call_tools(parent_response))
299
363
  print(f"\n\n{parent.name}: {parent_result}")
300
364
  query = ""
301
365
 
@@ -343,7 +407,7 @@ class Agent(BaseModel):
343
407
  async with aiofiles.open(AGENTS_FILE, 'r') as file:
344
408
  content = await file.read()
345
409
  agents = json.loads(content) if content else []
346
- agents.append(new_agent.model_dump())
410
+ agents.append(new_agent.dict())
347
411
 
348
412
  async with aiofiles.open(AGENTS_FILE, 'w') as file:
349
413
  await file.write(json.dumps(agents, indent=4))
@@ -409,7 +473,7 @@ class Agent(BaseModel):
409
473
  if agent.id == self.id:
410
474
  agents[index] = self
411
475
 
412
- updated_agents.append(agent.model_dump())
476
+ updated_agents.append(agent.dict())
413
477
 
414
478
  async with aiofiles.open(AGENTS_FILE, 'w') as file:
415
479
  await file.write(json.dumps(updated_agents, indent=4))