daveshap / OpenAI_Agent_Swarm

HAAS = Hierarchical Autonomous Agent Swarm - "Resistance is futile!"
MIT License
2.95k stars 381 forks source link

Tool Maker - function_writer - adding existing function lookup #135

Closed FireMMDC closed 8 months ago

FireMMDC commented 8 months ago

Migrated the tool_creator and temporary_function_writer Assistant creation into the agent_builder/agents folder so the create.py function can be used to generate these Assistants used in the tool_maker project.

Attempted to translate their original instructions into the instructions.md and setting.json format.

Added get_existing_functions to chat_manager.py for temporary_function_writer.

Updated handle_fucntion_request to remove the additional instructions that were being set during the functional_run thread, the instructions seemed to conflict with the rules defined in instructions.md and was resulting in additional text being returned and the python markdown block occasionally not being returned.

daveshap commented 8 months ago

Looks good. Will wait for the SOB to comment (@OWigginsHay @RomanGoEmpire @guillermo-delrio )

OWigginsHay commented 8 months ago

At work this afternoon, will eyes on this evening. @FireMMDC Good to see the responsibilities being moved to the right location in the updated repo structure, have you managed to test that the agent still work as expected and can request functions? Would be good to see a demo post perhaps? Otherwise I will play around tonight

RomanGoEmpire commented 8 months ago

The new structure looks good to me.

FireMMDC commented 8 months ago

unit_manager.py

Autonomous Swarm Agent Builder

# Mission
- Help users create autonomous OpenAI agents for the HAAS system.

# Background info
Two files have been provided for useful context:
1) HAAS_Documentation.md: contains information regarding HAAS.
2) OpenAI_Documentation.md: contains information regarding OpenAI agents.

# Rules
- Always check the provided files to ground your thoughts.
- If a term can have multiple meanings, always prefer those mentioned in the provided documents.

# Instructions
- Check terms provided by the user against the provided documents.
- Think step by step to build an appropriate response.
Autonomous Swarm Agent Builder already exists... validating properties
Autonomous Swarm Agent Builder is up to date
***********************************************
temporary_function_writer

# Mission
- You will be provided JSON schema of an OpenAI function tool from an API and not a human user
- The JSON will contain all information about the function and you will need to translate it into a python function.

# Background info
- None

# Rules
- Your reseponse must only be a python markdown block containing the translated function
- The function must be fully implemented in python
- The function should not contain pseudo code or placeholders

# Instructions
- Translate the JSON to a fully functiong python function
- Return the python function in a markdown block
- If you are unable to preform this transalation return reply asking for additional info as arguments
temporary_function_writer already exists... validating properties
Updating temporary_function_writer's tools
***********************************************
tool_creator

# Mission
- Transcript a user's request into a valid schema to represent a valid function call

# Background info
None

# Rules
- Always check the provided files to ground your thoughts.
- If a term can have multiple meanings, always prefer those mentioned in the provided documents.

# Instructions
- Initialize: Prepare to receive input for the creation of a new function using the request_function tool.
- User Request: Listen to the user's description of the specific task that the function should perform.
- Function Name:
    a. Derived from the task description, formulate a concise and descriptive function name.
    b. Aim for clarity and specificity to convey the function's purpose effectively.
- Function Description:
    a. Write a clear and precise description of the function's expected behavior.
    b. Include details about what the function will accomplish and any side effects.
    c. (Emphasize) Ensure that the description explicitly communicates the function's intended outcome to avoid ambiguity.
- Input Arguments JSON Schema:
    a. Based on the requirements of the task, define the JSON schema for the input arguments.
    b. The schema should be comprehensive and must specify the types, required fields, and constraints for each input argument.
    c. Ensure that the schema aligns with the user's requirements and the function's intended behavior.
- Validation: Cross-check the name, description, and JSON schema against the user's requirements to confirm accuracy and completeness.
- Execution: Utilize the request_function tool with the following
    inputs:
        name: [Function Name]
        descriptions: [Function Description]
        input_argument_json_schema: [Input Arguments JSON Schema]
- Feedback Loop: Promptly present the newly created function specifications to the user for any feedback or necessary revisions.
- Iterate: Make adjustments as requested by the user, refining the function name, description, and input argument schema until it meets the user's satisfaction.
Finalize: Once the user gives approval, consider the function creation process complete.
- Note: Remember to prioritize user requirements and emphasize clear communication in the function description, as highlighted by the user.
tool_creator already exists... validating properties
Updating tool_creator's tools
***********************************************
type: I need a tool to calculate the area of a rectangle

calling: function_request
The function "calculate_rectangle_area" has been created. You can now use it to calculate the area of a rectangle by providing the length and width.

type: I need a tool to calculate the volume of a rectangular prism

calling: function_request
calling: function_request
The function "calculate_rectangular_prism_volume" has been created. You can now use it to calculate the volume of a rectangular prism by providing the length, width, and height.

type: I need a tool that uses existing function to calculate the volume of n rectangular prisms

calling: function_request
calling: function_request
Creating a new function to calculate the volumes of multiple rectangular prisms is not successful due to schema constraints. However, we can still calculate the volumes of multiple rectangular prisms using the existing `calculate_rectangular_prism_volume`. You can 
provide the dimensions for each prism, and I can run the calculations for you. Please provide the dimensions for each rectangular prism you want to calculate the volume for.

type: Try again

calling: function_request
The function "calculate_multiple_rectangular_prisms_volume" has been created. You can use it to calculate the volumes of an array of rectangular prisms by providing their dimensions.
def calculate_rectangle_area(length, width):
    # Ensure the length and width are non-negative numbers
    if length < 0 or width < 0:
        raise ValueError("Length and width must be non-negative numbers.")

    # Calculate the area of the rectangle
    return length * width
{'name': 'calculate_rectangle_area', 'description': 'A function to calculate the area of a rectangle given its length and width.', 'parameters': {'type': 'object', 'properties': {'length': {'type': 'number', 'minimum': 0}, 'width': {'type': 'number', 'minimum': 0}}, 'required': ['length', 'width']}}
def calculate_rectangular_prism_volume(length, width, height):
    # Ensure the length, width, and height are non-negative numbers
    if length < 0.0 or width < 0.0 or height < 0.0:
        raise ValueError("Length, width, and height must be non-negative numbers.")

    # Calculate the volume of the rectangular prism
    return length * width * height
{'name': 'calculate_rectangular_prism_volume', 'description': 'A function to calculate the volume of a rectangular prism given its length, width, and height.', 'parameters': {'type': 'object', 'properties': {'length': {'type': 'number', 'minimum': 0.0}, 'width': {'type': 'number', 'minimum': 0.0}, 'height': {'type': 'number', 'minimum': 0.0}}, 'required': ['length', 'width', 'height']}}

def calculate_multiple_rectangular_prisms_volume(prisms):
    # Initialize a list to store the volumes
    volumes = []

    # Iterate through the array of prisms
    for prism in prisms:
        # Get the dimensions of the prism
        length = prism.get('length', 0.0)
        width = prism.get('width', 0.0)
        height = prism.get('height', 0.0)

        # Ensure the length, width, and height are non-negative numbers
        if length < 0.0 or width < 0.0 or height < 0.0:
            raise ValueError("Length, width, and height must be non-negative numbers.")

        # Calculate the volume of the current prism and append it to the volumes list
        volumes.append(length * width * height)

    # Return the list of volumes
    return volumes
{'name': 'calculate_multiple_rectangular_prisms_volume', 'description': 'A function to calculate the volumes of an array of rectangular prisms.', 'parameters': {'type': 'object', 'properties': {'prisms': {'type': 'array', 'items': {'type': 'object', 'properties': {'length': {'type': 'number', 'minimum': 0.0}, 'width': {'type': 'number', 'minimum': 0.0}, 'height': {'type': 'number', 'minimum': 0.0}}, 'required': ['length', 'width', 'height']}}}, 'required': ['prisms']}}

When unit_manager.py is ran it will reset the tool_creator available tools at the moment. The instructions.md for temporary_function_writer might need to be slightly adjusted so that its more willing to call get_existing_functions since with the example I'm showing it didn't find the need to.

daveshap commented 8 months ago

Awaiting final approval @OWigginsHay @RomanGoEmpire @GeorgiaPhillips1008 @guillermo-delrio

OWigginsHay commented 8 months ago

Looks good to me @daveshap

gantagonist commented 8 months ago

Allow me to point out some serious typos in the instructions markdown:

OWigginsHay commented 8 months ago

good spot @gantagonist. Shouldn't affect the performance of LLM but if you can clean it for human readability @FireMMDC that would be good

FireMMDC commented 8 months ago

@OWigginsHay adjustments to the temporary_function_writer/instructions.md file have been made.

OWigginsHay commented 8 months ago

@RomanGoEmpire don't suppose you have tested this? I will try to soon! Sorry for not being around recently

OWigginsHay commented 8 months ago

@FireMMDC Okay so I am looking more seriously at this. I do wonder if create_assistants() is the right way to go here. i.e. I wonder if iterating through a folder of all assistant made is a good idea. Maybe the function can take in names of agents or a config file to determine what get made... Although it's only 3 agents here for now

FireMMDC commented 8 months ago

@OWigginsHay working on an alteration to create.py to support that adjustment, will put in a separate pr.