fetch-logo
ConceptsConceptsGuidesGuidesExamplesExamplesReferencesReferencesAPIsAPIs
GitHub (opens in a new tab)
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
  • Guides
      • Quickstart
        • What's an Agent?
        • uAgents Framework installation
        • Create your first agent
        • Agents address
        • Communicating with other agents
        • Agent Handlers (on_...)
        • Agents storage functions
        • Public and private Agents
        • Send tokens with Agents
        • Agents Mailboxes
        • Agent Functions
        • Make agents AI Engine compatible
          • from ai_engine
        • Multi-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
        • Options for running local agents
        • Hosted agent
        • Introducing dialogues
        • Almanac Contract
        • Verify messages with Agents
        • Multi-file agent pipeline for AI Engine: Network of Primary and Secondary functions in Agentverse
        • Localwallet
        • Agentverse: Hosted Agents
        • Agentverse: Dice Roll agent
        • Agentverse: Allowed Imports
        • Agentverse: Mailbox
        • Register Agentverse Functions
        • Agentverse Functions: coin toss agent
        • Field descriptions for DeltaV
        • Agentverse Command Line Interface (AVCTL)
        • AVCTL Hosting commands
      • Agents and Functions creation APIs
      • Secret Management APIs
      • How to convert native FET to and from ERC-20 FET
      • How to stake FET tokens
      • Different ways of staking FET
      • Re-delegating staked FET token
      • Reconciliation service
      • How to setup a Multisig Wallet
        • Getting started
        • How to use the Fetch wallet
        • How to stake and claim rewards
        • Address book
        • Connections
        • Fetch Wallet Hardware Connection Guide
        • Installation
        • Connecting to a blockchain
        • Querying balances
        • Wallets and private keys
        • Sending funds
        • Staking
        • Smart contracts
          • Stake auto-compounder
          • Stake optimizer
          • Oracles
          • Wallet top-up
          • Liquidity pool
          • Swap automation
        • Installation️
        • Getting started
        • Keys
          • How to add profiles
          • How to add contract templates
          • How to compile contracts
          • How to deploy contracts
          • Contract interaction
        • Installation
        • How to use chain state snapshots
        • State-synchronization (state-sync)
        • How to set up a validator node
        • How to join a testnet
        • How to run a single node test network
        • Governance
        • How to get testnet tokens via the Token Faucet
          • CLI - Introduction
          • CLI - Managing keys
          • CLI - Managing tokens
          • CLI - Multisig keys
          • CLI - Delegation
          • Governance proposals
      • Agents 101
      • Agents 101 for AI Engine
Guides
AI Agents
Intermediate topics
Make agents AI Engine compatible
ℹ️

This article is a work-in-progress. It will be expanded rapidly.

Make your agents AI Engine compatible

In the previous resource, (Agent functions ↗️) we created a simple agent that returned a dice roll, however this agent was already ready to be callable by AI Engine ↗️. Let's get into how.

from ai_engine

To enable communication from agents to the AI Engine, we import 3 objects that define the allowed responses:

  1. UAgentResponseType():

    class UAgentResponseType(Enum):
        FINAL = "final"
        ERROR = "error"
        VALIDATION_ERROR = "validation_error"
        SELECT_FROM_OPTIONS = "select_from_options"
        FINAL_OPTIONS = "final_options"
    • We used FINAL in our dice roll ↗️ example:

          await ctx.send(
              sender, UAgentResponse(message=str(result), type=UAgentResponseType.FINAL)
          )

      UAgentResponseType.FINAL tells us that the message has no other responses.

    • We can use ERROR to signify the agent has encountered an error:

          await ctx.send(sender, UAgentResponse(message="Unexpected Error", type=UAgentResponseType.ERROR))
       
    • UAgentResponseType.SELECT_FROM_OPTIONS gives the user who is interacting with AI Engine options to select from, you could build this like so:

              options = []
              ctx_storage = {}
              for idx, value in enumerate(response):
                  options.append(KeyValue(key=idx, value=value))
              if options:
                  await ctx.send(
                      sender,
                      UAgentResponse(
                          options=options,
                          type=UAgentResponseType.SELECT_FROM_OPTIONS,
                          request_id=request_id
                      )
                  )
    • UAgentResponseType.FINAL_OPTIONS signals the end of the options to AI Engine:

              options = [KeyValue(key=x, value=x) for x in result if len(x) > 1]
              await ctx.send(
                  sender,
                  UAgentResponse(options=options, type=UAgentResponseType.FINAL_OPTIONS),
              )
  2. The AI Engine also enforces key and value to be strings:

    class KeyValue(Model):
        key: str
        value: str
  3. UAgentResponse it an extension of the UAgents response type:

    class UAgentResponse(Model):
        version: Literal["v1"] = "v1"
        type: UAgentResponseType
        request_id: Optional[str]
        agent_address: Optional[str]
        message: Optional[str]
        options: Optional[List[KeyValue]]
        verbose_message: Optional[str]
        verbose_options: Optional[List[KeyValue]]

    We don't need to alter UAgentResponse, using as UAgentResponse(message=message, type=UAgentResponseType.*) will satisfy current requirements.

Was this page helpful?

Agent FunctionsMulti-file agent pipeline for AI Engine: Hugging face API to create a multi agent pipeline
footer-logo

Main website

Integrations

Events

We’re hiring!

Twitter (opens in a new tab)Telegram (opens in a new tab)Discord (opens in a new tab)GitHub (opens in a new tab)Youtube (opens in a new tab)LinkedIn (opens in a new tab)Reddit (opens in a new tab)
Sign up for developer updates