@@ -11,6 +11,7 @@ The official Python library for the [HelpingAI](https://helpingai.co) API - Adva
1111- ** OpenAI-Compatible API** : Drop-in replacement with familiar interface
1212- ** Emotional Intelligence** : Advanced AI models with emotional understanding
1313- ** Tool Calling Made Easy** : [ ` @tools decorator ` ] ( HelpingAI/tools/core.py:144 ) for effortless function-to-tool conversion
14+ - ** Direct Tool Execution** : Simple ` .call() ` method for executing tools without registry manipulation
1415- ** Automatic Schema Generation** : Type hint-based JSON schema creation with docstring parsing
1516- ** Universal Tool Compatibility** : Seamless integration with OpenAI-format tools
1617- ** Streaming Support** : Real-time response streaming
@@ -201,6 +202,45 @@ response = hai.chat.completions.create(
201202print (response.choices[0 ].message.content)
202203```
203204
205+ ### Direct Tool Execution
206+
207+ The HAI client provides a convenient ` .call() ` method to directly execute tools without having to manually use the registry:
208+
209+ ``` python
210+ from HelpingAI import HAI
211+ from HelpingAI.tools import tools
212+
213+ @tools
214+ def search (query : str , max_results : int = 5 ):
215+ """ Search the web for information"""
216+ # Implementation here
217+ return {" results" : [{" title" : " Result 1" , " url" : " https://example.com" }]}
218+
219+ # Create a client instance
220+ client = HAI()
221+
222+ # Directly call a tool by name with arguments
223+ search_result = client.call(" search" , {" query" : " python programming" , " max_results" : 3 })
224+ print (" Search results:" , search_result)
225+
226+ # You can also execute tools from model responses
227+ response = client.chat.completions.create(
228+ model = " Dhanishtha-2.0-preview" ,
229+ messages = [{" role" : " user" , " content" : " search for quantum computing" }],
230+ tools = get_tools(),
231+ tool_choice = " auto"
232+ )
233+
234+ # Extract tool name and arguments from the model's tool call
235+ tool_call = response.choices[0 ].message.tool_calls[0 ]
236+ tool_name = tool_call.function.name
237+ tool_args = json.loads(tool_call.function.arguments)
238+
239+ # Execute the tool directly
240+ tool_result = client.call(tool_name, tool_args)
241+ print (f " Result: { tool_result} " )
242+ ```
243+
204244### Advanced Tool Features
205245
206246#### Type System Support
@@ -318,11 +358,9 @@ def divide_numbers(a: float, b: float) -> float:
318358# Handle tool execution in your application
319359def execute_tool_safely (tool_name : str , arguments : dict ):
320360 try :
321- tool = get_registry().get_tool(tool_name)
322- if not tool:
323- return {" error" : f " Tool ' { tool_name} ' not found " }
324-
325- return tool.call(arguments)
361+ # You can use the direct call method instead of registry manipulation
362+ hai = HAI()
363+ return hai.call(tool_name, arguments)
326364
327365 except ToolExecutionError as e:
328366 print (f " Tool execution failed: { e} " )
0 commit comments