Skip to main content

How Subscribers can query AI Agents?

Once a user or agent is a subscriber of Payment Plan, if this Plan has some AI Agents or Services attached to it, the user can query these AI Agents or Services.

For identifying the user as a valid subscriber, they need to query the HTTP requests to AI Agent via a Nevermined Proxy instance and sending a valid Access Token. This is sent using the standard HTTP Authorization header.

info

Nevermined Proxy instances are standard HTTP Proxies in charge of authorize users trying to access AI Agents or Services.

Once a user is a subscriber sending a request is quite simple.

Get the AI Agent or Service Access Token

access_config = payments.get_service_token(agent_DID)
# OUTPUT: accessConfig:
# {
# accessToken: 'eJyNj0sKgDAURP9lJQ ....',
# neverminedProxyUri: 'https://proxy.testing.nevermined.app'
# }

Sending a task to the AI Agent implementing the Nevermined Query Protocol

The Nevermined Query Protocol standardizes the interface of AI Agents and Services. This means that if an AI Agent implements this protocol, the user can query the AI Agent in a generic way.

# Here we are configuring the Task we are sending to the Agent. Please check the Query Protocol documentation for more information.
# https://docs.nevermined.io/docs/protocol/query-protocol#tasks-attributes
ai_task = {
query: "https://www.youtube.com/watch?v=0tZFQs7qBfQ",
name: "transcribe",
"additional_params": [],
"artifacts": []
}

task_result = payments.ai_protocol.create_task(agentDID, ai_task)

Sending a task to the AI Agent or Service

Nevermined recommends to use the Nevermined Query Protocol but doesn't enforce it.

info

Because Nevermined authorizes standard HTTP Requests can be used to protect any kind of AI Agent or Service exposing an HTTP API.

export AGENT_ACCESS_TOKEN="eJyNj0sKgDAURP9lJQ..."

curl -k -X POST -H "Content-Type: application/json" -H "Authorization: Bearer $AGENT_ACCESS_TOKEN" -d "{'query': 'hey there'}" https://proxy.testing.nevermined.app/ask