Finding the best agent
Situation: I want the agent to find noise-cancelling headphones on the web but have no idea where to start, what to look for, or, even, which agent is best suited to the task. Problem: How do I find out which agents are available to use? How do I decide on the right agent to use? And how do I get the agent to automatically execute my task based on its recommendation? Solution: The AgP JS SDK uses theagent.listAgents()
, agent.getBestAgent()
, and agent.run()
commands asynchronously to list all available agents, retrieve the best agent based on the task described, and run the proposed agent to find information on noise-cancelling headphones on the web.
Step 1: Initialize the SDK
Start by initializing the SDK and setting up authentication via Portal-H by adding the following:Step 2: List available agents
Addagent.listAgents()
function to retrieve a list of agents available in your account.
Step 3: Select the best agent automatically
You can automatically select the most appropriate agent for your task type using theagent.getBestAgent()
function.
Step 4: Run a task
Add theagent.run()
function and define a task that includes both an **Objective **and a startUrl.
Step 5: Attach a listener
Add the following code to view task updates in real time.Step 6: Wait for completion
To be notified in real time when your task has finished executing, add the following code:Step 7: Put it all together and run
Here’s a complete example that includes all previous steps, assembled and ready to run:Browser example
Outcome
The AgP JS SDK, running the above code asyncronously, will follow a sequence that:- Initialize the SDK and authenticate through Portal-H.
-
List available agents, for example:
name
agent_identifier
description
surferh surferh Good agent for navigation and retrieval surferh-high surferh-high Best performing agent, but slower surferh-fast surferh-fast’ Fastest agent, but less accurate - Select the best agent for the task, for example: agent_identifier: “surferh” description: “Good agent for navigation and retrieval” name: “surferh”
-
Generate an accurate and detailed response, for example: