- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
2 hours ago
Agentic AI and GraphQL
This is a guide for anyone interested in the intersection of Agentic AI and GraphQL, two powerful technologies and how they can be used with the Now platform.
We will start with the assumption that you have no experience with either and give you the need-to-know behind the technologies and how they are used to unleash the power of workflows on the Now platform. By Part 5 you will be a pro! We will go into the background behind both GraphQL and Agentic AI but if you are interested in more information I would suggest reading the introduction from the GraphQL Org before starting this just to get some familiarity with terms and some of the benefits of GraphQL versus REST.
Inspiration from this article series was drawn from Setting up and Testing your first GraphQL API Tutorial by @Jon G Lind.
Note: Initially we planned for this article to have a narrower focus strictly on leveraging Agentic AI, but the use case assumes GraphQL knowledge and thus turned from 2 parts into 5. If you already are a GraphQL pro you can skip straight to part 4!
Part 2 GraphQL Beyond the Basics
Part 3 GraphQL Security & Testing
Part 4 Agentic AI and GraphQL Basics
Part 5 Agentic AI and GraphQL Advanced
Instructions for Starting From Part 4
Note: Unfortunately this tutorial cannot be done in a personal developer instance due to limitations on the capabilities that PDIs are given.
If you skipped the GraphQL parts please follow these steps to get caught up, everyone else feel free to skip! First things first to work on this tutorial you need an instance with the Now Assist AI Agents[sn_aia] plugin activated. Once you are in your instance just commit the following update sets
- User GraphQL Tutorial.xml
- User GraphQL Tutorial Demo Data.xml
Agentic Workflows Basics
Let us start off with some definitions from the ServiceNow Docs
- Agentic workflows solve business problems with agentic AI. In AI Agent Studio, you must define an agentic workflow and connect it with an AI agent to execute complex goals involving variable data or other factors that traditional automation can struggle with.
- AI agents contain a set of large language model (LLM) instructions and tools that can perform specific tasks.
- Tools provide your AI agents with the capabilities necessary to complete their tasks. When adding tools, consider how the AI agent will use them to achieve its objectives as well as how those tools interact with each other. Providing your AI agents with the appropriate tools help ensure the robustness and quality of their performance.
Basically you can think of things in this structure with a one to many relationship at each layer of the hierarchy
- Agentic Workflow
- Agent A
- Tool 1
- Tool 2
- Agent B
- Tool 3
- Agent A
You can have up to 100 agents (10 is the recommended maximum) per Agentic Workflow and up to 5 tools (reasonable limit before you make another agent) per agent. The reason for these limits are that agents should have clear defined purposes so they really should not need that many tools to accomplish their job. There is an AI Agent Orchestrator who is directing the agents to fulfill tasks to complete the workflow. Think of the agents as working together guided by an intelligence that will try to return the best results based on what the role of the agent.
Note: If older versions you may see "use cases" instead of the rebranded term "agentic workflows". Throughout this guide, I will be using agentic workflows, but if you are on an older version, just know that they are the same thing.
Creating an Agentic Workflow
We're going to create an Agentic Workflow intended for use by HR representatives. Go to AI Agent Studio > Create and manage. In the Agentic Workflows tab click new and fill it out roughly like the below. We recommend using the ‘Use Now Assist’ button. Its important to give clear instructions If you are interested in tweaking the instructions of your agentic workflows look at this post for more advanced guidance.
Description
This AI agent is designed to look up user information based on a user input of username and specific requested information. It is intended for use by authorized personnel who need to quickly access user details.
Instructions
1. Extract the username and specific requested information from the user input.
2. Validate the username and requested information for correctness and completeness.
3. Search the user information database for the specified username.
4. Retrieve the requested information associated with the username.
5. Present the retrieved information to the user in a clear and concise format.
You can go ahead and click through the Save and Continue button until you get to the Select display tab. Turn on the Now Assist panel, click the arrow next to it, set the only role to user_admin. Click Save and test and then type anything and you should get something like this
This makes sense as we did not give the agentic workflow any agents to fulfill tasks. So it is like we created a flow with a description and no steps. In this scenario we kept the instructions really simple. You can be explicit and get quite robust on precise steps, error handling, quality control, etc.; for tips on that look to this post.
Creating an AI Agent
Go back to the Create and manage tab and in the Agentic Workflows tab click into the Get and Update User Data agentic workflow. On the Describe and instruct tab locate the Connect AI Agents section. Click the arrow next to the Add AI agent button and click Create New AI Agent. Let us configure it like so
Keeping it really simple, click Save and continue until you end up on the testing page.
Creating a Tool
This section is going to dive into Flow Designer to use that as our connection to GraphQL API. There are different options that the tool can use we find subflows to be some of the easiest to work with but what we are trying to do is quite a bit simpler since we can rely on GraphQL API so we are going to start with an action. In a new tab open up Process Automation > Flow Designer. Click New > Action and give it a name like "Get User Information". Click Build action.
Now we are going to need to pass in the query so click Create Input and fill it out like so
Then click the little blue plus icon and select the Payload Builder step (likely says something about deprecation; info here). The goal is to make something like this which will build us a JSON object
Now we are going to click the lower blue plus icon in order to add our REST step after the Payload Builder step. Before we continue let us create a new user
- "agent_user_admin" (remember when we set user_admin in the Agentic Workflow?)
- give them the user_admin role
- make sure to set their password, note it down, and set Password needs reset to false
We are going to set Connection to Define Connection Inline and for the Credential Alias click the plus icon and then select Basic Auth Credentials. Use your agent_user_admin credentials
When you are creating the Credential alias make sure to set it to Credential instead of Connection and Credential. I have filled out a few other fields like so
- Set the HTTP Method to POST
- Set the Base URL
- Set the Resource Path
Scroll down and also set the Request Body to the Payload from your Payload Builder step.
Now that we have the REST step complete add an output using the Outputs tab. Label of Response Body and then exit edit mode and map the Response Body from the REST Step to the Response Body output.
You should be able to Save and Test now. You can use a basic query and look through the steps to validate it is working, go ahead and Publish it.
query {
snc {
userGraphQLTutorial {
getUser(userID: "david.loo") {
name
email
}
}
}
}
Wiring Everything Up
Go back to AI Agent Studio > Create and manage and go to the AI Agents tab and select the User Information Agent you created. Go to the Add tools and information tab and select Add tool > Flow action. Set it to something like this
Use this description for your tool
Use this action to retrieve user information through the User GraphQL Tutorial schema.
Provide a GraphQL query that follows the schema structure below.
Important details:
- Application namespace: snc
- Schema namespace: userGraphQLTutorial
- userID corresponds to the user’s user_name field. You have to get that information from the user via user input
Example Query
query {
snc {
userGraphQLTutorial {
getUser(userID: "david.loo") {
name
}
}
}
}
Schema Reference
schema {
query: Query
}
type Query {
getUser(userID: String!): User
}
type User {
userID: String! @source(value: "user_name.value")
name: String! @source(value: "name.display_value")
email: String! @source(value: "email.value")
manager: User! @source(value: "manager.value")
department: Department @source(value: "department.value")
}
type Department {
name: String! @source(value: "name.display_value")
departmentHead: User @source(value: "dept_head.value")
}
Click Save and continue until you end up on the testing screen. Then click the Create and manage at the top and click into your User Information Lookup Agent. Scroll down and click the Add AI Agent button and add the User Information Agent.
Click through the Save and continue until you end up on the testing page. At this point we have wired up a tool calling our GraphQL API to an agent to an agentic workflow and we are ready to test a semi-basic use case. Let us test the agentic workflow, in Task try "What is the name and email of the manager and department head of david.loo". You should get something like
You can try out different requests, word of caution I experienced some inconsistency (our MVP apparently is not ready for primetime).
Part 5 Agentic AI and GraphQL
After completing this part, you should be comfortable creating an Agentic Workflow, Agents, creating tools, and how to test them. Finally, the grand finale! Part 5 Agentic AI and GraphQL Advanced will greatly expand on the intersection between Agentic AI and GraphQL and the power of using these 2 tools together! We will fully flesh out the use case and manipulate user data.