Python API to query Dialog Cx agent

I have an active Dialog CX agent, and I wish to test its response for a large set of queries. Is there an API interface (Python is preferred) to query an agent and collect its response?

Solved Solved
0 5 202
1 ACCEPTED SOLUTION

Hello amirdolev,

Here are some troubleshooting steps you can try:

1. Check Authentication
2. Verify Session Path
3. Verify Language Code
4. Check for Errors

Here's an example of how you can modify your code to include error handling:

try:
response = session_client.detect_intent(request=request)
print("=" * 20)
print(f"Query text: {response.query_result.text}")
response_messages = [
" ".join(msg.text.text) for msg in response.query_result.response_messages
]
print(f"Response text: {' '.join(response_messages)}\n")
except Exception as e:
print(f"Error occurred: {e}")

View solution in original post

5 REPLIES 5

Thanks, that was very helpful.

I don't get any response when I try it, and the script hangs on the "response = session_client.detect_intent(request=request)" line. I know the agent is alive since I can interact with it through the integrated HTML interface.

any idea?

Make sure that you have set the authentication properly! by default it uses the local gcloud credentials

Hello amirdolev,

Here are some troubleshooting steps you can try:

1. Check Authentication
2. Verify Session Path
3. Verify Language Code
4. Check for Errors

Here's an example of how you can modify your code to include error handling:

try:
response = session_client.detect_intent(request=request)
print("=" * 20)
print(f"Query text: {response.query_result.text}")
response_messages = [
" ".join(msg.text.text) for msg in response.query_result.response_messages
]
print(f"Response text: {' '.join(response_messages)}\n")
except Exception as e:
print(f"Error occurred: {e}")

Yes, you can use the Dialogflow CX API to query your agent and collect its responses programmatically.