AgentX-Dev 0.1.1__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.
@@ -0,0 +1,96 @@
1
+ Metadata-Version: 2.4
2
+ Name: AgentX-Dev
3
+ Version: 0.1.1
4
+ Summary: A lightweight LLM agent framework with standard and structured tool support use, prompt management, and support for OpenAI.
5
+ Author-email: Bruce-Arhin Shadrach <brucearhin098@gmail.com>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/shadrach098/Bruce_framework
8
+ Project-URL: Source, https://github.com/shadrach098/Bruce_framework
9
+ Requires-Python: >=3.8
10
+ Description-Content-Type: text/markdown
11
+ Requires-Dist: openai>=1.0.0
12
+ Requires-Dist: pydantic>=2.0
13
+ Requires-Dist: google-generativeai
14
+ Requires-Dist: httpx
15
+
16
+
17
+ # 🧠 Bruce Agent
18
+
19
+ **AgentX** is a lightweight, extensible agentic framework for building custom LLM agents with structured tool use, prompt templates, and integration with OpenAI and Gemini models.
20
+
21
+ ## 🚀 Features
22
+
23
+ - 🔁 Custom reasoning loop (`AgentRunner`)
24
+ - 🧩 Structured tool execution (Pydantic-based)
25
+ - 💬 Prompt templating and management
26
+ - 🔌 LLM-agnostic: supports **OpenAI function calling** and **Google Gemini**
27
+ - 🪄 Easy-to-use API for building agents
28
+
29
+ ## 📦 Installation
30
+
31
+ published to PyPI:
32
+
33
+ ```sh
34
+ pip install AgentX-Dev
35
+ ```
36
+
37
+ ## Example use
38
+
39
+ ```python
40
+ from AgentXL import AgentRunner, AgentType,ChatModel
41
+ from pydantic import BaseModel
42
+ from AgentXL.Tools import StructuredTool
43
+ # Define a sample tool
44
+ class MultiplyTool(StructuredTool):
45
+ name = "multiply"
46
+ description = "Multiply two numbers"
47
+
48
+ class Schema(BaseModel):
49
+ a: int
50
+ b: int
51
+
52
+ def run(self, a: int, b: int) -> int:
53
+ return a * b
54
+
55
+ # Create chat model and agent
56
+ ReAct=AgentType.ReAct
57
+ chat_model = ChatModel.GPT(model="gpt-4", temperature=0.7)
58
+ tools = [MultiplyTool()]
59
+ agent = AgentRunner(model=chat_model,Agent=ReAct, tools=tools)
60
+
61
+ response = agent.Initialize("What is 5 times 8?")
62
+ print(response.content)
63
+
64
+
65
+
66
+ ```
67
+
68
+ ``` bruce_framework/
69
+ ├── src/
70
+ │ └── bruce_framework/
71
+ │ ├── __init__.py
72
+ │ ├── agent/
73
+ │ │ ├── __init__.py
74
+ │ │ └── agent.py
75
+ │ ├── runner/
76
+ │ │ ├── __init__.py
77
+ │ │ └── agent_run.py
78
+ │ └── chatmodel.py
79
+ ├── README.md
80
+ ├── LICENSE
81
+ └── pyproject.toml
82
+
83
+ ```
84
+
85
+ ## 📚 Documentation (Coming Soon)
86
+ ### More tutorials, tool examples, and structured prompting guides coming soon.
87
+
88
+ ## 🧑‍💻 Author
89
+ #### Bruce-Arhin Shadrach
90
+ #### 📧 brucearhin098@gmail.com
91
+ #### 🌐 GitHub
92
+
93
+ 📝 License
94
+ MIT License
95
+
96
+
@@ -0,0 +1,81 @@
1
+
2
+ # 🧠 Bruce Agent
3
+
4
+ **AgentX** is a lightweight, extensible agentic framework for building custom LLM agents with structured tool use, prompt templates, and integration with OpenAI and Gemini models.
5
+
6
+ ## 🚀 Features
7
+
8
+ - 🔁 Custom reasoning loop (`AgentRunner`)
9
+ - 🧩 Structured tool execution (Pydantic-based)
10
+ - 💬 Prompt templating and management
11
+ - 🔌 LLM-agnostic: supports **OpenAI function calling** and **Google Gemini**
12
+ - 🪄 Easy-to-use API for building agents
13
+
14
+ ## 📦 Installation
15
+
16
+ published to PyPI:
17
+
18
+ ```sh
19
+ pip install AgentX-Dev
20
+ ```
21
+
22
+ ## Example use
23
+
24
+ ```python
25
+ from AgentXL import AgentRunner, AgentType,ChatModel
26
+ from pydantic import BaseModel
27
+ from AgentXL.Tools import StructuredTool
28
+ # Define a sample tool
29
+ class MultiplyTool(StructuredTool):
30
+ name = "multiply"
31
+ description = "Multiply two numbers"
32
+
33
+ class Schema(BaseModel):
34
+ a: int
35
+ b: int
36
+
37
+ def run(self, a: int, b: int) -> int:
38
+ return a * b
39
+
40
+ # Create chat model and agent
41
+ ReAct=AgentType.ReAct
42
+ chat_model = ChatModel.GPT(model="gpt-4", temperature=0.7)
43
+ tools = [MultiplyTool()]
44
+ agent = AgentRunner(model=chat_model,Agent=ReAct, tools=tools)
45
+
46
+ response = agent.Initialize("What is 5 times 8?")
47
+ print(response.content)
48
+
49
+
50
+
51
+ ```
52
+
53
+ ``` bruce_framework/
54
+ ├── src/
55
+ │ └── bruce_framework/
56
+ │ ├── __init__.py
57
+ │ ├── agent/
58
+ │ │ ├── __init__.py
59
+ │ │ └── agent.py
60
+ │ ├── runner/
61
+ │ │ ├── __init__.py
62
+ │ │ └── agent_run.py
63
+ │ └── chatmodel.py
64
+ ├── README.md
65
+ ├── LICENSE
66
+ └── pyproject.toml
67
+
68
+ ```
69
+
70
+ ## 📚 Documentation (Coming Soon)
71
+ ### More tutorials, tool examples, and structured prompting guides coming soon.
72
+
73
+ ## 🧑‍💻 Author
74
+ #### Bruce-Arhin Shadrach
75
+ #### 📧 brucearhin098@gmail.com
76
+ #### 🌐 GitHub
77
+
78
+ 📝 License
79
+ MIT License
80
+
81
+
@@ -0,0 +1,32 @@
1
+ [project]
2
+ name = "AgentX-Dev"
3
+ version = "0.1.1"
4
+ description = "A lightweight LLM agent framework with standard and structured tool support use, prompt management, and support for OpenAI."
5
+ authors = [{ name = "Bruce-Arhin Shadrach", email = "brucearhin098@gmail.com" }]
6
+ license = "MIT"
7
+ readme = "README.md"
8
+ requires-python = ">=3.8"
9
+
10
+ dependencies = [
11
+ "openai>=1.0.0",
12
+ "pydantic>=2.0",
13
+ "google-generativeai",
14
+ "httpx"
15
+ ]
16
+
17
+ [project.urls]
18
+ Homepage = "https://github.com/shadrach098/Bruce_framework"
19
+ Source = "https://github.com/shadrach098/Bruce_framework"
20
+
21
+ [build-system]
22
+ requires = ["setuptools>=61.0", "wheel"]
23
+ build-backend = "setuptools.build_meta"
24
+
25
+ [tool.setuptools]
26
+ package-dir = {"" = "src"}
27
+
28
+ [tool.setuptools.packages.find]
29
+ where = ["src"]
30
+
31
+
32
+
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,342 @@
1
+ """
2
+ This module contains classes and functions for working with agent prompts and JSON data.
3
+
4
+ It includes classes for different agent prompt templates, a function to convert strings to JSON,
5
+ and a container class for standard pre-defined agent prompt templates.
6
+ """
7
+
8
+ import yaml,logging,json,uuid,time
9
+ from pydantic import BaseModel, Field, ValidationError
10
+ from typing import Dict, Any,Type,Optional,List
11
+ from rich.console import Console
12
+ console=Console()
13
+ # Set up logging
14
+ logging.basicConfig(level=logging.ERROR)
15
+ logger = logging.getLogger(__name__)
16
+
17
+ class StandardParser(BaseModel):
18
+ """
19
+ A Pydantic model representing the standard parser.
20
+
21
+ Attributes:
22
+ - action: str, the action to take.
23
+ - action_input: str or Dict, the input to the action.
24
+
25
+ Methods:
26
+ - from_json: Creates an instance from a JSON string.
27
+ """
28
+ action: str = Field("The action to take", alias='action')
29
+ action_input: str | Dict = Field("The input to the action", alias='action_input')
30
+
31
+ class Config:
32
+ populate_by_name = True
33
+
34
+ @classmethod
35
+ def from_json(cls, json_str: str):
36
+ try:
37
+ json_object = convert_to_json(json_str)
38
+ if isinstance(json_object,dict):
39
+ return cls(**json_object)
40
+ elif isinstance(json_object,str):
41
+ return json_object
42
+ except (ValueError, ValidationError) as e:
43
+ logger.error(f"Error creating StandardParser instance: {e}")
44
+ raise
45
+
46
+
47
+
48
+
49
+
50
+
51
+ def load_prompt_templates(file_path: str) -> Dict:
52
+ """
53
+ Loads prompt templates from a YAML file.
54
+
55
+ Args:
56
+ - file_path: str, the path to the YAML file containing the prompt templates.
57
+
58
+ Returns:
59
+ - Dict: A dictionary containing the loaded prompt templates.
60
+ """
61
+ with open(file_path, 'r') as yaml_:
62
+ return yaml.safe_load(yaml_)
63
+
64
+ system = load_prompt_templates('promptTemplate.yaml')
65
+
66
+
67
+ def convert_to_json(json_str: str) -> Dict[str, Any]:
68
+ """
69
+ Converts a given string into a JSON object.
70
+
71
+ Args:
72
+ - json_str: str, the string to be converted into JSON.
73
+
74
+ Returns:
75
+ - Dict[str, Any]: A dictionary representing the JSON object.
76
+
77
+ Raises:
78
+ - json.JSONDecodeError: If the input string is not valid JSON.
79
+ """
80
+ try:
81
+ if json_str.startswith("```json") and json_str.endswith("```"):
82
+ return json.loads(json_str.split("```json")[-1].split("```")[0])
83
+ elif json_str.startswith('{') and json_str.endswith('}'):
84
+ return json.loads(json_str)
85
+ else :
86
+ return json_str
87
+ except json.JSONDecodeError as e:
88
+ logger.error(f"Failed to decode JSON: {e}")
89
+ return {} # or you can re-raise the exception, depending on your error handling strategy
90
+
91
+ # Consider adding a Config class to these models to allow population by field name
92
+ class Instruction_Tuned_(BaseModel):
93
+ """
94
+ A Pydantic model representing the Instruction-Tuned prompt template.
95
+
96
+ Attributes:
97
+ - action: str, the action to take or final answer.
98
+ - action_input: str or Dict, the input to the action.
99
+
100
+ Methods:
101
+ - from_json: Creates an instance from a JSON string.
102
+ """
103
+ action: str = Field("The action to take OR Final Answer", alias="action")
104
+ action_input: str | Dict = Field("The input to the action OR You should put what you want to return to use here and return to user immediately", alias="action_input")
105
+
106
+
107
+ @classmethod
108
+ def from_json(cls, json_str: str):
109
+ try:
110
+ json_object = convert_to_json(json_str)
111
+ if isinstance(json_object,dict):
112
+ return cls(**json_object)
113
+ elif isinstance(json_object,str):
114
+ return json_object
115
+ except (ValueError, ValidationError) as e:
116
+ # Handle the error, e.g., log it, raise a custom exception, or return a default value
117
+ error = f"Error creating Instruction_Tuned_ instance: {e}"
118
+ logger.error(error)
119
+ raise
120
+
121
+
122
+ class React_(BaseModel):
123
+ """
124
+ A Pydantic model representing the ReAct prompt template.
125
+
126
+ Attributes:
127
+ - Thought: str, the agent's thoughts.
128
+ - action: str, the action to take or final answer.
129
+ - action_input: str or Dict, the input to the action.
130
+
131
+ Methods:
132
+ - from_json: Creates an instance from a JSON string.
133
+ """
134
+ Thought: str = Field('The Agent Thoughts', alias='Thought')
135
+ action: str = Field("The action to take OR Final Answer", alias="action")
136
+ action_input: str | Dict = Field("The input to the action OR You should put what you want to return to use here and return to user immediately", alias="action_input")
137
+
138
+ @classmethod
139
+ def from_json(cls, json_str: str):
140
+ try:
141
+ json_object = convert_to_json(json_str)
142
+ if isinstance(json_object,dict):
143
+ console.print("[bold cyan]Thinking...[/bold cyan]")
144
+ print(f"\n{json_object['Thought']}")
145
+ return cls(**json_object)
146
+ elif isinstance(json_object,str):
147
+ return json_object
148
+ except (ValueError, ValidationError) as e:
149
+ # Handle the error, e.g., log it, raise a custom exception, or return a default value
150
+ error = f"Error creating React_ instance: {e}"
151
+ logger.error(error)
152
+ raise
153
+
154
+ class ChainOfThought(BaseModel):
155
+ """
156
+ A Pydantic model representing the Chain-of-Thought prompt template.
157
+
158
+ Attributes:
159
+ - Thought: str, the step-by-step reasoning.
160
+ - Action: str, the action to take or final answer.
161
+ - Action_Input: str or Dict, the input to the action.
162
+
163
+ Methods:
164
+ - from_json: Creates an instance from a JSON string.
165
+ """
166
+ Thought: str = Field('The step-by-step reasoning', alias='Thought')
167
+ Action: str = Field("The action to take or Final Answer", alias='Action')
168
+ Action_Input: str | Dict = Field("The input to the action", alias='Action Input')
169
+
170
+ @classmethod
171
+ def from_json(cls, json_str: str):
172
+ try:
173
+ json_object = convert_to_json(json_str)
174
+ if isinstance(json_object,dict):
175
+ console.print("[bold cyan]Thinking...[/bold cyan]")
176
+ print(f"\n{json_object['Thought']}")
177
+ return cls(**json_object)
178
+ elif isinstance(json_object,str):
179
+ return json_object
180
+ except (ValueError, ValidationError) as e:
181
+ logger.error(f"Error creating ChainOfThought instance: {e}")
182
+ raise
183
+
184
+ class ZeroShot(BaseModel):
185
+ """
186
+ A Pydantic model representing the Zero-Shot prompt template.
187
+
188
+ Attributes:
189
+ - action: str, the action to take.
190
+ - action_input: str or Dict, the input to the action.
191
+
192
+ Methods:
193
+ - from_json: Creates an instance from a JSON string.
194
+ """
195
+ action: str = Field("The action to take", alias='action')
196
+ action_input: str | Dict = Field("The input to the action", alias='action_input')
197
+
198
+ @classmethod
199
+ def from_json(cls, json_str: str):
200
+ try:
201
+ json_object = convert_to_json(json_str)
202
+ if isinstance(json_object,dict):
203
+ return cls(**json_object)
204
+ elif isinstance(json_object,str):
205
+ return json_object
206
+ except (ValueError, ValidationError) as e:
207
+ logger.error(f"Error creating ZeroShot instance: {e}")
208
+ raise
209
+
210
+ class FewShot(BaseModel):
211
+ """
212
+ A Pydantic model representing the Few-Shot prompt template.
213
+
214
+ Attributes:
215
+ - action: str, the action to take.
216
+ - action_input: str or Dict, the input to the action.
217
+
218
+ Methods:
219
+ - from_json: Creates an instance from a JSON string.
220
+ """
221
+ action: str = Field("The action to take", alias='action')
222
+ action_input: str | Dict = Field("The input to the action", alias='action_input')
223
+
224
+ @classmethod
225
+ def from_json(cls, json_str: str):
226
+ try:
227
+ json_object = convert_to_json(json_str)
228
+ if isinstance(json_object,dict):
229
+ return cls(**json_object)
230
+ elif isinstance(json_object,str):
231
+ return json_object
232
+ except (ValueError, ValidationError) as e:
233
+ logger.error(f"Error creating FewShot instance: {e}")
234
+ raise
235
+
236
+
237
+ class AgentFormattor(BaseModel):
238
+ prompt: str
239
+ Agent: Type[BaseModel]=Field(description="The agent that will under the prompt and extract what's needed")
240
+
241
+ @classmethod
242
+ def Formattor(cls,prompt:str,Agent:Type[BaseModel]):
243
+ return cls(prompt=prompt,Agent=Agent)
244
+
245
+
246
+ class AgentPrompt:
247
+ """
248
+ Manages and formats the prompt template for the agent, allowing for
249
+ flexible placeholder values.
250
+ """
251
+ def __init__(self, prompt: str):
252
+ """
253
+ Initializes the prompt with a template string.
254
+ """
255
+ self.prompt = prompt
256
+
257
+ def format(self, tools: List,user_hold, **kwargs: Any) -> str:
258
+ """
259
+ Formats the prompt template with dynamic values.
260
+
261
+ Args:
262
+ tools (List): A list of tool objects to populate {tools} and {tool_names}.
263
+ **kwargs (Any): Optional. Any other key-value pairs corresponding to
264
+ placeholders in the template (e.g., user_input="...").
265
+ Returns:
266
+ str: The fully formatted prompt.
267
+ """
268
+ # Build the dictionary of values that are always available.
269
+ format_values = {
270
+ 'tools': "\n".join([f"- {t.name}: {t.description}" for t in tools]),
271
+ 'tool_names': ", ".join([t.name for t in tools]),
272
+ 'user_input' : user_hold
273
+
274
+ }
275
+
276
+ # The update() method merges the optional kwargs.
277
+ # If kwargs is empty, this does nothing.
278
+ format_values.update(kwargs)
279
+
280
+ # format_map uses the combined dictionary to fill in the template.
281
+ return self.prompt.format_map(format_values)
282
+
283
+
284
+
285
+
286
+ class AgentType:
287
+ """
288
+ A container for standard, pre-defined agent prompt templates.
289
+
290
+ This class holds various prompt styles as class attributes, making them
291
+ easy to access and use to initialize an AgentPrompt.
292
+
293
+ Example:
294
+ react_prompt_template = AgentType.ReAct
295
+ agent_prompt = AgentPrompt(template=react_prompt_template)
296
+ """
297
+
298
+ ReAct = AgentFormattor.Formattor(prompt=system['ReAct'],Agent=React_)
299
+ Instruction_Tuned = AgentFormattor.Formattor(prompt=system['Instruction-Tuned'],Agent=Instruction_Tuned_)
300
+ Chain_of_Thought = AgentFormattor.Formattor(prompt=system['Chain-of-Thought'],Agent=ChainOfThought)
301
+ Zero_Shot = AgentFormattor.Formattor(prompt=system['Zero-Shot'],Agent=ZeroShot)
302
+ Few_Shot = AgentFormattor.Formattor(prompt=system['Few-Shot'],Agent=FewShot)
303
+
304
+
305
+
306
+
307
+ class ToolCall(BaseModel):
308
+ name: str
309
+ args: Dict[str, Any]
310
+ result: str
311
+
312
+
313
+ class ToolCall(BaseModel):
314
+ name: str
315
+ args: Dict[str, Any]
316
+ result: str
317
+
318
+ class AgentCompletion(BaseModel):
319
+ id: str
320
+ object: str = "agent.completion"
321
+ created: int
322
+ model: str
323
+ query: str
324
+ content: str
325
+ tool_calls: List[ToolCall] = []
326
+ steps: List[str] = []
327
+ history: Optional[List[Dict[str, str]]] = None
328
+
329
+
330
+ @classmethod
331
+ def from_agent(cls, *, model_name: str, query: str, content: str, tool_calls: List[ToolCall], steps: List[str], history: List[Dict[str, str]]):
332
+ return cls(
333
+ id=str(uuid.uuid4()),
334
+ created=int(time.time()),
335
+ model=model_name,
336
+ query=query,
337
+ content=content,
338
+ tool_calls=tool_calls,
339
+ steps=steps,
340
+ history=history
341
+ )
342
+
@@ -0,0 +1,11 @@
1
+ from .Agent import AgentFormattor,AgentPrompt,AgentType,AgentCompletion,StandardParser,ToolCall
2
+
3
+
4
+ __all__ =[
5
+ 'AgentFormattor',
6
+ 'AgentCompletion',
7
+ 'AgentPrompt',
8
+ 'AgentType',
9
+ 'StandardParser',
10
+ 'ToolCall'
11
+ ]