Connect applications to agents
This tutorial shows you how to connect a JavaScript application to a SkillFlaw agent.
With an agent, your application can use any connected tools to retrieve more contextual and timely data without changing any application code. The tools are selected by the agent's internal LLM to solve problems and answer questions.
Prerequisites
- Install and start SkillFlaw
- Create a SkillFlaw API key
- If you plan to use the JavaScript example, use Node.js 18+ or another runtime with
fetchsupport - Create an OpenAI API key
This tutorial uses an OpenAI LLM. If you want to use a different provider, you need a valid credential for that provider.
Create an agent flow
The following steps modify the Simple Agent template to connect a Directory component and a Web Search component as tools for an Agent component. The Directory component loads all files of a given type from a target directory on your local machine, and the Web Search component performs a DuckDuckGo search. When connected to an Agent component as tools, the agent has the option to use these components when handling requests.
-
In SkillFlaw, click New Flow, and then select the Simple Agent template.
-
Remove the URL and Calculator tools, and then add Directory and Web Search components to your flow.
-
In the Directory component's Path field, enter the directory path and file types that you want to make available to the Agent component.
In this tutorial, the agent needs access to a record of customer purchases, so the directory name is
customer_ordersand the file type is.csv. Later in this tutorial, the agent will be prompted to findemailvalues in the customer data.You can adapt the tutorial to suit your data, or, to follow along with the tutorial, you can download
customer-orders.csvand save it in acustomer_ordersfolder on your local machine. -
In the Directory and Web Search components' header menus, enable Tool Mode so you can use the components with an agent.
-
Connect the Directory and Web Search components' Toolset ports to the Agent component's Tools port.
-
In the Agent component, enter your OpenAI API key.
If you want to use a different provider or model, edit the Model Provider, Model Name, and API Key fields accordingly.
-
To test the flow, click Playground, and then ask the LLM a question, such as
Recommend 3 used items for carol.davis@example.com, based on previous orders.Given the example prompt, the LLM would respond with recommendations and web links for items based on previous orders in
customer_orders.csv.The Playground prints the agent's chain of thought as it selects tools to use and interacts with functionality provided by those tools. For example, the agent can use the Directory component's
as_dataframetool to retrieve a DataFrame, and the Web Search component'sperform_searchtool to find links to related items.
Add a Prompt Template component to the flow
In this example, the application sends a customer's email address to the SkillFlaw agent. The agent compares the customer's previous orders within the Directory component, searches the web for used versions of those items, and returns three results.
-
To include the email address as a value in your flow, add a Prompt Template component to your flow between the Chat Input and Agent components.
-
In the Prompt Template component's Template field, enter
Recommend 3 used items for {email}, based on previous orders.Adding the{email}value in curly braces creates a new input in the Prompt Template component, and the component connected to the{email}port is supplying the value for that variable. This creates a point for the user's email to enter the flow from your request. If you aren't using thecustomer_orders.csvexample file, modify the input to search for a value in your dataset.At this point your flow has six components. The Chat Input component is connected to the Prompt Template component's email input port. Then, the Prompt Template component's output is connected to the Agent component's System Message input port. The Directory and Web Search components are connected to the Agent component's Tools port. Finally, the Agent component's output is connected to the Chat Output component, which returns the final response to the application.
