Agents
Agents serve two main purposes in Dojo:
- Metric tracking. Each agent records the state of its cryptocurrency portfolio and other statistics at every block in the simulation.
- Reward function. This function defines how you measure the "success" of your policy. For example you might want to track your total wealth, or impermanent loss, etc. If you use dojo to optimize a parameterized policy, the reward can be designed in combination with the policy such that the policy tries to maximize it's value.
Agents are NOT responsible for making decisions on how to act in the environment. That is the job of the policies.
In-built Metrics Tracking
The base class implements some pre-existing metrics tracking functionality:
quantity(token: str) -> float
: get the agent quantity of a token, can be either the address OR the symbol.portfolio() -> Portfolio
: get the agent portfolio, e.g.{"USDC": 1000, "ETH": 10, "UNI-V3-POS": 1}
.erc20_portfolio() -> Portfolio
: get the agent portfolio of ERC20 tokens, e.g.{USDC: 1000}
.erc721_portfolio() -> Dict[str, list]
: get the agent portfolio of ERC721 NFTs, e.g.{"UNI-V3-POS": [251300]}
.wealth(date: datetime) -> Decimal
: returns the value of the agent's portfolio in USD.done() -> bool
: get whether the agent is done or not, defaults to done if the agent goes broke.reward(obs: BaseObservation) -> float
: user defined reward metric.
You can access the documentation for the latest functionality of agents on our package docs.
Creating an Agent
Here is a basic demo for creating your own agent. You just need to implement your reward
function.