Develop AI Agent¶
Overview¶
In this guide, you will:
Create a simple AI agent that provides personal assistance. We will define a GraphQL schema with a query that invokes the inline agent to generate dynamic responses based on input parameters. The agent runs within the resolver logic and returns results directly as part of the GraphQL response.
Prerequisites¶
Before you begin, make sure you have the following:
- Visual Studio Code: Install Visual Studio Code if you don't have it already.
- WSO2 Integrator: BI Extension: Install the WSO2 Integrator: BI extension. Refer to Install WSO2 Integrator: BI for detailed instructions.
- Get OpenAI key:
- Sign up at OpenAI.
- Get an API key from the API section.
Step 1: Create a new integration project¶
- Click on the BI icon in the sidebar.
- Click on the Create New Integration button.
- Enter the project name as
GraphqlService. - Select the project directory by clicking on the Select Location button.
-
Click the Create New Integration button to generate the integration project.
Step 2: Create a GraphQL service¶
- Click the + button on the WSO2 Integrator: BI side panel or navigate back to the design screen and click on Add Artifact.
- Select GraphQL Service under the Integration as API artifacts.
-
Keep the default Listener and Service base path configurations, and click Create.
Step 3: Create a GraphQL resolver¶
- Click the + Create Operations button in the GraphQL design view.
- In the side panel, click the + button in the Mutation section to add a mutation operation.
- Provide
taskas the value for the Field name. - Click the Add Argument button to add a GraphQL input
- Provide
queryfor the Argument name. - Provide
stringfor the Argument type. - Click Add to save the argument.
- Provide
-
Provide
string|errorfor the Field type, as this will be used as the return type of the resolver.
Step 4: Implement the resolving logic with an inline agent¶
- Click the created
taskoperation in the side panel to navigate to the resolver editor view. - Click the + button in the flow to open the side panel.
- Click Agent under Statement, which will navigate you to the agent creation panel.
- Update Variable Name to
response. This is the variable where the agent's output will be stored. - Update the Role and Instructions to configure the agent’s behavior.
- Provide the query parameter as the input for Query. This will serve as the command that the agent will execute.
- Click Save.
- Next, configure the agent’s memory, model, and tools. For guidance, refer to the Chat Agent configuration steps and the Personal Assistant setup guide to make the agent function as a personal assistant.
- After configuring the agent, click the + button on the flow and select Return under Control from the side panel.
-
For the Expression, provide the
responsevariable as the input.
At this point, we've created a GraphQL resolver that takes a user-provided query as input, passes it to an inline agent for processing, and returns the agent’s response as the result of the resolver.
Note
You must implement a query operation to have a valid GraphQL service. Similar to creating the task operation in Step 3, add an operation named greet by pressing the + button in the Query section, without any input parameters. For the implementation, you can simply return a string literal saying "welcome".




