Quickstart

Before you begin

  • Python 3.11 or later must be installed on your machine

  • Giza CLI must be installed on your machine. You can install it by running pip install giza-cli

  • Actions-SDK should be installed with the extra agents. You can install it by running pip install giza-actions[agents]

  • You must have an active Giza account. If you don't have one, you can create one here.

  • You must have a model version deployed on Giza as an endpoint. You can follow the tutorial Build a Verifiable Neural Network with Giza Actions to deploy an MNIST model on Giza.

  • During the tutorial, you will need to interact with the Giza CLI, Ape's framework, and provide multiple inputs, like model-id, version-id, account name, etc.

  • You have to be logged in to the Giza CLI or have an API KEY.

Setup

Get up and running with Agents! In this quickstart you will learn the basics to get up and running with Agents and Giza Platform. As Agents are an extension of Actions it is encouraged that you are familiarised with it first before jumping right into Agents, for more information here is the Actions documentation.

Before you begin, make sure you have all the necessary libraries installed:

$ pip install giza-actions[agents]
$ pipx install giza-cli

From your terminal, create a Giza user through our CLI in order to access the Giza Platform:

giza users create

After creating your user, log into Giza:

giza users login

Optional: you can create an API Key for your user in order to not regenerate your access token every few hours.

giza users create-api-key

To create Actions Runs you will need a Giza Workspace, create it executing the following command in your terminal:

giza workspaces create

Create your first Agent

To create a new agent an endpoint should have been deployed prior. If you don't have one, please follow this tutorial Build a Verifiable Neural Network with Giza Actions.

Create an Account

The first step will be to create an account (wallet) using Ape's framework this will be the account that we will use to sign the transactions of the smart contract. We can do this by running the following command and providing the required data. It will ask you for a passphrase, make sure to save it in a safe place as it will be used to unlock the account when signing:

$ ape accounts generate <account name>
Enhance the security of your account by adding additional random input:
Show mnemonic? [Y/n]: n
Create Passphrase to encrypt account:
Repeat for confirmation:
SUCCESS: A new account '0x766867bB2E3E1A6E6245F4930b47E9aF54cEba0C' with HDPath m/44'/60'/0'/0/0 has been added with the id '<account name>'

We encourage the creation of a new account for each agent, as it will allow you to manage the agent's permissions and access control more effectively, but importing accounts is also possible.

Fund the account

Before we can create an AI Agent, we need to fund the account with some ETH. You can do this by sending some ETH to the account address generated in the previous step.

If you are using Sepolia testnet, you can get some testnet ETH from a faucet like Alchemy Sepolia Faucet or LearnWeb3 Faucet. If you are on mainnet you will need to transfer funds to it.

Create an Agent using the CLI

With a funded account we can create an AI Agent. We can do this by running the following command

giza agents create --model-id <model-id> --version-id <version-id> --name <agent name> --description <agent description>

The information needed is:

  • model-id: the id of the model used in the endpoint

  • version-id: the id of the version used in the endpoint

  • name: name for the agent

  • description: an optional description of the agent

This command will prompt you to use an ape account, specify the one that you want to use and it will create the agent.

Now you are set to use an Agent through code and interact with smart contracts

from giza_actions.agents import GizaAgent

# A environment variable of <ACCOUNT_NAME>_PASSPHRASE must be in the environment
# This is needed to decrypt the account and sign transactions
agent = GizaAgent(
    id=<model-id>,
    version_id=<version-id>,
    contracts={
        # Contracts uses <alias>:<contract-address> dict
        "mnist": "0x17807a00bE76716B91d5ba1232dd1647c4414912",
        "token": "0xeF7cCAE97ea69F5CdC89e496b0eDa2687C95D93B",
        },
    # Specify the chain that you are using
    chain="ethereum:sepolia:geth",
)

result = agent.predict(input_feed=[42], verfiable=True)

# This is only using read functions, so no need to sign
with agent.execute() as contracts:
    # Accessing the value will block until the prediction is verified
    if result.value > 0.5:
        # Read the contract name
        result = contracts.mnist.name()
        print(result)
    elif result.value < 0.5:
        # Read the contract name
        result = contracts.token.name()
        print(result)

What’s next?

Congrats! πŸŽ‰ Now that you’ve completed the Agents quickstart, check out our guides and learn how to do more specific things in our how-to-guides and tutorials. If you’re interested in learning more about Actions core concepts, grab a cup of coffee and take a look at our Conceptual Guides!

Last updated