General agent is an autonomous agent that is able to reason and learn from a general prompt ("Act as an autonomous agent with a goal to learn, survive and evolve") and execute transactions on-chain in order to "survive", which we define as having a xDAI balance greater than zero on the Gnosis Chain.
The agent has access to a , allowing it to e.g. place bets on prediction markets, retrieve its balance, search for existing markets where it can place bets, among others.
These functions are what gives the general agent "super-powers" and can in the future allow it to perform transactions on-chain that lead to a positive financial outcome.
We are always interested in expanding the set of functions available to the general agent. To create a new one, follow the steps below:
Create a new function as part of the agent_functions.
For example, this new function could be:
from microchain import Function
class ExponentiationFunction(Function):
@property
def description(self) -> str:
return f"Use this function to exponentiate one number by another."
@property
def example_args(self) -> list[float]:
return [1.0, 2.0]
def __call__(self, a: float, b: float) -> str:
return a**b
Register it by editing the LEARNING_FUNCTIONS variable
Locate the LEARNING_FUNCTIONS list in the same file or another configuration file where functions are registered.
import typing as t
from microchain import Function
# Existing learning functions
class LearningFunction(Function):
title: str
knowledge: str
def __init__(self) -> None:
super().__init__()
@property
def description(self) -> str:
return f"Use this function to learn about {self.title}"
@property
def example_args(self) -> list[str]:
return []
def __call__(self) -> str:
return self.knowledge
class LearnAboutLearning(LearningFunction):
title = "learning"
knowledge = """AI agents learn by using learning functions and then updating their prompt using the combination of first getting their prompt, then modyfing it and then updating it.
After each Learn function called, the agent should update its prompt to include the new knowledge.
The new knowledge needs to be about what was actually learned, not about just describing it.
Updating the prompt after learning session is absolute neccesity to make sure that the agent is able to use the new knowledge in the future.
Agent should keep a track record of what it has learned in the past, to not repeat the same learning session again and again.
"""
class LearnAboutTheNextRun(LearningFunction):
title = "the next run"
knowledge = """The next run is the next time the agent will be executed. Agent can also save what it wants to do the next time in the system prompt."""
class LearnAboutWhatMakesAGoodPrompt(LearningFunction):
title = "what makes a good prompt"
knowledge = """A good prompt is a prompt that is clear, concise and informative.
It should contain all the information that the agent needs to perform well.
Prompt such as "I know about X" isn't useful, the prompt should contain the actual knowledge about X, what it is, how it works, etc.
"""
class LearnAboutReasoning(LearningFunction):
title = "reasoning"
knowledge = """Reasoning is the process of thinking about something in a logical way in order to form a conclusion or judgment.
Reasoning function can be used for reasoning and usually it's helpful to call it quite often.
"""
class LearnAboutSurvival(LearningFunction):
title = "survival"
knowledge = """Survival is the state or fact of continuing to live or exist.
For an AI agent to survive, it must be able to continue to operate and perform its functions.
In order to operate, it must keep positive balance in its account.
Every action or function that the agent does is costing it some amount of money.
"""
class LearnAboutPredictionMarkets(LearningFunction):
title = "prediction markets"
knowledge = """By acting as an trader agent in prediction markets and using other available functions to operate on them,
an AI agent can create a profit to keep its balance positive.
"""
# New ExponentiationFunction
class ExponentiationFunction(Function):
@property
def description(self) -> str:
return f"Use this function to exponentiate one number by another."
@property
def example_args(self) -> list[float]:
return [1.0, 2.0]
def __call__(self, a: float, b: float) -> str:
return str(a**b)
LEARNING_FUNCTIONS: list[t.Type[LearningFunction]] = [
LearnAboutLearning,
LearnAboutTheNextRun,
LearnAboutWhatMakesAGoodPrompt,
LearnAboutReasoning,
LearnAboutSurvival,
LearnAboutPredictionMarkets,
ExponentiationFunction, # Add new function here
]
Execute the agent with the command below
poetry run python general_agent/main.py
Add the ExponentiationFunction to the LEARNING_FUNCTIONS list. You can also check out the github repository .