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.
Check out the AI Engine package (opens in a new tab) to download it and start integrating your Agents with this tool!
Current version of the package is .
Prerequisites
Make sure you have read the following resource before going on with this guide:
from ai_engine
To enable communication from agents to the AI Engine, we import 3 objects that define the allowed responses:
-
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), )
-
-
The AI Engine also enforces
key
andvalue
to be strings:class KeyValue(Model): key: str value: str
-
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 asUAgentResponse(message=message, type=UAgentResponseType.*)
will satisfy current requirements.⚠️Whenever operating on DeltaV, we encourage everyone to select the Next Generation AI Engine personality type. This AI Engine personality stands as a significant AI Engine personality type offering enhanced scalability, reliability, and flexibility. The major key features include advanced context understanding, improved function recommendations, and the ability to handle multiple dialogue formats.