from nalona import Agent, Tool, TaskForce
from nalona.llms import Gemini
# Initialize your LLM
llm = Gemini()
# Define tools
def say_hello(name: str):
return f"Hello there, {name}! 👋"
def calculate(equation: str):
return eval(equation)
hello_tool = Tool(func=say_hello,
description="Greets the user by name.",
params={'name': {'description': 'The name to greet.', 'type': 'str', 'default': 'unknown'}})
calculate_tool = Tool(func=calculate,
description="Evaluates an equation.",
params={'equation': {'description': 'The equation to evaluate.', 'type': 'str', 'default': 'unknown'}})
# Create agents
greeter = Agent(llm=llm,
tools=[hello_tool],
identity="Friendly Greeter",
verbose=True)
math_magician = Agent(llm=llm,
tools=[calculate_tool],
identity="Math Magician",
verbose=True)
# Assemble your task force!
force = TaskForce(agents=[greeter, math_magician], caching_dir='cache')
force.start_force()
force.execute_agent(greeter, "Hi I am mervin")
force.execute_agent(math_magician, "2+2")
force.exit_force()
This example demonstrates creating agents with tools and using a TaskForce to manage execution.
🧐 Important Questions
What does record_result func do?
The record_result function is used to save the result of an agent's workflow. This can be useful for passing one agent's response to another.
This concludes in the scalability and simplicity of the architecture.
🚀 Advanced Features
Multi-LLM Support: Seamlessly switch between different language models
Custom Tool Creation: Easily create and integrate your own tools
Response Validation: Ensure output quality with built-in validation
Easy Passing of Information: Share information between agents with ease using the record_result function
Scalable Architecture: Build large-scale AI agent networks with the TaskForce class
📈 Performance and Scalability
a1zo is designed for efficiency:
Lightweight core for minimal overhead
Scalable architecture for complex agent networks
Actual Use Case:
from nalona.llms import Gemini
from nalona import Agent, Tool, TaskForce
from nalona.tools import get_current_time, web_search
import os
def list_dir():
"""Returns a list of items in the current working directory."""
try:
items = os.listdir()
return items
except OSError as e:
print(f"Error listing directory: {e}")
return []
def write_to_file(filename:str, content:str):
"""Writes the given content to a file with the specified filename.
Args:
filename (str): The name of the file to write to.
content (str): The content to write to the file.
"""
try:
with open(filename, 'w') as f:
f.write(content)
print(f"Successfully wrote to '{filename}'")
except OSError as e:
print(f"Error writing to file: {e}")
def gcd(a:int, b:int):
"""
Calculate the Greatest Common Divisor (GCD) of two numbers using the Euclidean algorithm.
Parameters:
a (int): The first number.
b (int): The second number.
Returns:
int: The GCD of the two numbers.
"""
while b:
a, b = b, a % b
return a+b
llm_instance = Gemini()
# Define the tools using the OwnTool class
write_tool = Tool(
func=write_to_file,
description="Writes the given content to a file to the given filename in dir",
returns_value=False,
llm = llm_instance,
verbose=True
)
list_tool = Tool(
func=list_dir,
description="Provides the list of files and folders in current working dir.",
returns_value=True,
llm = llm_instance,
verbose=True
)
time_tool = Tool(
func=get_current_time,
description="Provides the current time.",
returns_value=True,
llm = llm_instance,
verbose=True
)
web_tool = Tool(
func=web_search,
description="Provides web search result on the given query.",
returns_value=True,
llm = llm_instance,
verbose=True
)
# Initialize the language model instance
content_saver = Agent(
llm=llm_instance,
identity="content_saver",
tools=[write_tool],
verbose=True,
description="A content saver which can save any content in markdown format to a given file.",
expected_output="In markdown format",
)
researcher = Agent(
llm=llm_instance,
identity="researcher",
tools=[time_tool, web_tool],
description="A researcher having access to web and can get info about any topic.",
expected_output="A summary of the research",
verbose=True,
)
writer = Agent(
llm=llm_instance,
identity="writer",
tools=[],
description="A writer which can write on any topic with information.",
expected_output="In markdown format",
verbose=True,
)
# Define the task force
task_force = TaskForce(
agents=[content_saver, researcher, writer],
caching_dir="cache",
)
# Run the task force
task_force.start_force()
task_force.execute_agent(researcher, "What are wormholes?")
researcher_result = task_force.record_result(researcher)
print(researcher_result)
task_force.execute_agent(writer, f"Write an article on wormholes. Here is the information: {researcher_result}")
writer_result = task_force.record_result(writer)
task_force.execute_agent(content_saver, f"Save this information in wormholes.md: {writer_result}")
task_force.exit_force()
The Tools used from Nalona AI in the use case are totally experimental and are not recommended to use.