Programmatic agents and Knowledge Contexts Provisioning
Create agents sessions with programmatically provisioned Knowledge Contexts
Here’s a guide to create agent sessions with programmatically provisioned Knowledge Contexts. And then embed a programmatic agent in your web application using those agent sessions.
Default agent system
With the default agents system, your Mindset App admin dashboard manages access permissions for knowledge contexts assigned on an agent basis.
Programmatic agent system
You may need to provision agents and knowledge contexts access based on the permission system set up in your platform.
We’ve introduced the concept of an agent session: Agent sessions are programmatically provisioned on-demand for specified agents and knowledge contexts.
Once an agent session is created, providing the agentSessionUid
to the <mindset-agent>
HTML tag will allow you to embed the agent with the specified access permissions.
Tutorial : Embed a programmatic agent
In this Tutorial you will learn how to embed your programmatic agent in a web application.
Required parameters
You will need to get few parameters before starting.
YOUR-APP-UID is provided by the Mindset support team. All others parameters can be found in the Mindset Management Portal.
Parameter | Description |
---|---|
YOUR-APP-UID | Your appUid is provided by mindset. |
YOUR-MINDSET-API-KEY | Your Mindset API key. It is used to authenticate your API calls. |
AGENT-UID | The agent Uid you want the user chat with. You can find that Agent Uid in the setting of the agent in the Agent Management Portal. |
KNOWLEDGECONTEXT-1-UID | One Knowledge context Uid you want to provision the agent with |
KNOWLEDGECONTEXT-2-UID | Another one Knowledge context Uid you want to provision the agent with |
MINDSET-API-HOST | The Mindset API host. Used to call the Mindset API. |
Step 1: Create an agent session
To create an Agent Session (and hence create an agentSessionUid
required by the SDK), you will need to call the Mindset agentSessions API
. (See the Agent Sessions API documentation for more details).
We can imagine you would have to manage many agents, many knowledge contexts and many users in your platform.
According to your permissions and roles system, users
would have specific rights to access specific agents and specific Knowledge contexts
For example:
- A
User1
has the permission to use theagent1
provisioned with theKnowledge Context 1
andknowledge context 2
. - But a
User2
has the permission to use theagent1
provisioned with theKnowledge Context 1
Based on your permissions rules you will then create agent sessions
.
What we would like to achieve is :
- to provision the agent (
agentUid v8srU0hv88BeWBDcirSm
) - with the 2 knowledge contexts (
contextUids [qZJGsjytbM5fL15sfBui
,3am8rolEPXx3j0n132Bf
]) - and for a user with an
externalUserId
(user-x123456
).
We would need to provide the following parameters in the request body:
Below an example of a HTTP POST request to create that agent session.
The API response object will be:
The most important information that will be reused in the next step is the :
agentSessionUid
(v8srU0hv88BeWBDcirSm::uFKbuW0ipk2Za4QuQ6rx
).
Step 2: Embed the agent in your web application
You embed this agent using the same method you used to embed the default agent.
You will use the <mindset-agent>
HTML tag in your Front-end page:
But instead of providing the agentUid
you will provide the agentSessionUid
you just created in the previous step.
The final HTML tag will look like this:
Lifetime of Agent Session Access
Agent Sessions are intended to be generated on demand each time you create a web page that contains an embedded agent.
They become inactive after 31 days of non-use. They can also be deactivated immediately using the API.
We expect that you will create multiple agent sessions for the same user with identical agent and context details.
Please refer to the Agent Sessions API documentation for more details on how to manage agent sessions.
Reporting
Here’s how to set up reporting for agents.
When creating an agent session through the API, you can provide tags to the parmaters:
When initiating an agent session, the tags you specify are essential for understanding the interaction between agents, contexts, and users.
Adding tags enables you to view reports based on groups or filter activity according to the tags you’ve applied.
Please refer to the Agent Sessions API documentation for more information on adding tags.
Back-end and Front-end scripts full example
Back-end script
Sample back-end script (using express). It shows 2 end-points you can implement:
/api/getusertoken
which authenticate the user with Mindset system and returns anauthToken
/api/getagentsessionuid
which create an agent session and returns theagentSessionUid
Front-end script
A sample front-end script which:
- Provide a
getAuthToken()
method using your/api/getusertoken
end-point. - Provide a
getAgentSessionUid()
method using your/api/getagentsessionuid
end-point. - Build the
<mindset-agent>
html tag by passing theagentSessionUid
returned. - call
mindset.init()