Skip to content

Feature: plugin/tools with input params #753

@autonomous-spores

Description

@autonomous-spores
Image

Figure 1 illustrates the method for defining tools within swarms(line 47), utilizing an 'array' to dynamically load functions, such as fetch_current_weather. Below is a pseudocode example demonstrating a function with input parameters:

def fetch_current_weather(city: str) -> str:
	"""
	Fetches the current weather for a given city from the OpenWeatherMap API.
	Args:
	    city (str): The name of the city to fetch the weather for.
	
	Returns:
	    str: A formatted string of the current weather in the specified city.
	
	Raises:
	    ValueError: If the API response is invalid or the city is not found.
	"""
	try:
	    temperature = random.uniform(0.0, 1.0)
	    return f"The current weather in {city} with a temperature of {temperature}°C."
	
	except ValueError as e:
	    print(f"Value Error: {e}")
	    raise

The tools function by sending prompts, generated based on the annotations in the function above, to the agent to determine if the conversation between the LLM and the user includes a query about the weather.

For instance, consider the query, "How’s the weather in London today?" The program is expected to have "London" as the input and process it based on the LLM's response.

{
    "type": "function",
    "function": {
        "name": "fetch_current_weather",
        "parameters": {
            "city": "London"
        }
    }
}

Image

When implementing plugins in practice, it is essential to execute them with context-specific inputs, as demonstrated below. Ideally, we aim for the fetch_current_weather function to operate with a payload that accommodates variations.

def fetch_current_weather(payload: any, city: str) -> str:
	...
	...
	...

https://github.com/spore-swarm/autonomous-spores/blob/main/spores/core/runtime.py#L46

In the spores-swarm repository(we are building runtime module right now), we want it to be as shown in this link rather than as written at line 47.

kindly ask any ideas for this feature? or is there any alternative ways to get there, or will be featured in future?

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions