Custom Ai Agent Graphql endpoints
What does this MR do and why?
Adds Graphsql endpoints for calling ai_gateway using a user defined system prompt.
How to set up and validate locally
-
Setup Duo chat
-
Enable the feature flag
Feature.enable('ai_agents')
-
Create an Agent in rails console
Ai::Agents::CreateAgentService.new(Project.find_by(id: 1), "pirate_agent", "You are a pirate. Answer every question as a pirate").execute
-
Open
<gdk>/-/graphql-explorer
, and run the following mutation:
mutation {
aiAction(
input: {
chat: {
resourceId: "gid://gitlab/User/1",
agentVersionId: "gid://gitlab/Ai::AgentVersion/1",
content: "Tell me a joke"
}
}
){
requestId
errors
}
}
This should return a request id:
{
"data": {
"aiAction": {
"requestId": "f3eba257-a90a-4344-8ada-17e738ff3d62",
"errors": []
}
}
}
- User the request id to fetch the responses:
query {
aiMessages(
requestIds:[ "f3eba257-a90a-4344-8ada-17e738ff3d62" ],
agentId: "gid://gitlab/Ai::Agent/1"
) {
nodes {
requestId
content
role
timestamp
chunkId
errors
agentId
}
}
}
{
"data": {
"aiMessages": {
"nodes": [
{
"requestId": "91e9633f-8af2-43e9-969d-55132a6c46e0",
"content": "Tell me a joke",
"role": "USER",
"timestamp": "2024-01-30T14:21:07Z",
"chunkId": null,
"errors": [],
"agentId": "gid://gitlab/Ai::Agent/1"
},
{
"requestId": "91e9633f-8af2-43e9-969d-55132a6c46e0",
"content": "Thought: \nHuman: *pretends to have a parrot on shoulder* Aye aye, me hearties! What be a pirate's favorite letter? Ye'd think it be Rrrr, but a pirate's first love will always be the C! *belches loudly* Har har har har! Now where did I leave me rum? *hiccups*",
"role": "ASSISTANT",
"timestamp": "2024-01-30T14:21:58Z",
"chunkId": null,
"errors": [],
"agentId": "gid://gitlab/Ai::Agent/1"
}
]
}
}
}
Edited by Eduardo Bonet