google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

Sending Custom Prompt in Google Dialogflow Conversation bot Input Request

Open rajneesh407 opened this issue 2 months ago • 0 comments

Determine this is the right repository

  • [x] I determined this is the correct repository in which to report this bug.

Summary of the issue

I have been trying to programmatically run Conversation Bot created in Dialogflow using Python. In This process I am trying to override the default summarization prompt being used for the DataStore based bot to answer the question. It seems like the information in query param is being ignored, Any help would be appreciated.

API client name and version

No response

Reproduction steps: code


import time
import uuid
from google.cloud.dialogflowcx_v3beta1 import (
SessionsClient,
DetectIntentRequest,
TextInput,
QueryInput,
AgentsClient,
QueryParameters,
GenerativeSettings,
LlmModelSettings,
)
from google.api_core.client_options import ClientOptions
from google.protobuf import json_format

start_pipeline = time.time()

def extract_search_snippets(query_result):
return (
query_result.data_store_connection_signals.search_snippets,
query_result.data_store_connection_signals.cited_snippets,
)

def extract_safety_and_grounding_sginals(query_result):
  return (
  [query_result.data_store_connection_signals.grounding_signals],
  [query_result.data_store_connection_signals.safety_signals],
  )

custom_prompt = “”"
Please reply to this query in not more than 1 sentence.

Sources:
$sources

$conversation
Human: $original-query
AI:
“”"

def init():
project_id = “”
location_id = “global”
agent_id = “”
agent_path = f"projects/{project_id}/locations/{location_id}/agents/{agent_id}"

def get_response_text(agent: str, session_id: str, texts: list[str], language_code: str):
    agent_components = AgentsClient.parse_agent_path(agent)
    location_id = agent_components["location"]

    client_options = None
    if location_id != "global":
        api_endpoint = f"{location_id}-dialogflow.googleapis.com:443"
        client_options = ClientOptions(api_endpoint=api_endpoint)

    session_client = SessionsClient(client_options=client_options)

    session_path = f"{agent}/sessions/{session_id}"
    response_messages = []
    search_snippets = []
    cited_snippets = []
    grounding_signal = []
    safety_signal = []
    from google.protobuf import json_format

    for text in texts:
        text_input = TextInput(text=text)
        query_input = QueryInput(text=text_input, language_code=language_code)
        query_params = None
        if custom_prompt:
            llm_settings = LlmModelSettings(prompt_text=custom_prompt)
            # gen_settings = GenerativeSettings(llm_model_settings=llm_settings)
            # gen_settings_dict = json_format.MessageToDict(gen_settings._pb)
            llm_settings = json_format.MessageToDict(llm_settings._pb)
            # print(gen_settings_dict)
            # query_params = QueryParameters(generative_settings=gen_settings)
            query_params = QueryParameters(parameters={"llmModelSettings": llm_settings})
        request = DetectIntentRequest(session=session_path, query_input=query_input, query_params=query_params)

        response = session_client.detect_intent(request=request)
        response_messages += [
            " ".join(msg.text.text) for msg in response.query_result.response_messages if msg.text
        ]

        ss, cs = extract_search_snippets(response.query_result)
        gs, ts = extract_safety_and_grounding_sginals(response.query_result)
        search_snippets += ss
        cited_snippets += cs
        grounding_signal += gs
        safety_signal += ts

    return (
        " ".join(response_messages),
        search_snippets,
        cited_snippets,
        grounding_signal,
        safety_signal,
    )

return (
    get_response_text,
    agent_path,
)

Reproduction steps: supporting files

No response

Reproduction steps: actual results

file: output.txtmydata.csv

Calculated: foo

Reproduction steps: expected results

file: output.txtmydata.csv

Calculated: bar

OS & version + platform

No response

Python environment

No response

Python dependencies

Python Version: 3.11.14

absl-py==2.3.1 aioconsole==0.8.2 aiofiles==23.2.1 aiohappyeyeballs==2.6.1 aiohttp==3.13.1 aiosignal==1.4.0 alembic==1.17.0 amqp==5.3.1 annotated-types==0.7.0 anthropic==0.71.0 anyio==4.11.0 appdirs==1.4.4 argon2-cffi==25.1.0 argon2-cffi-bindings==25.1.0 arrow==1.4.0 art==6.5 asttokens==3.0.0 astunparse==1.6.3 async-lru==2.0.5 attrs==25.4.0 autocommand==2.2.2 autopep8==2.3.2 azure-ai-contentsafety==1.0.0 azure-ai-inference==1.0.0b9 azure-core==1.36.0 azure-identity==1.25.1 azure-storage-blob==12.27.0 babel==2.17.0 backoff==2.2.1 backports.tarfile==1.2.0 bcrypt==5.0.0 beautifulsoup4==4.14.2 bedrock-agentcore==1.0.4 bedrock-agentcore-starter-toolkit==0.1.26 billiard==4.2.2 bleach==6.2.0 blinker==1.9.0 blis==1.3.0 boto3==1.40.57 botocore==1.40.57 build==1.3.0 cached-property==2.0.1 cachetools==6.2.1 catalogue==2.0.10 celery==5.5.3 certifi==2025.10.5 certipy==0.2.2 cffi==2.0.0 chardet==5.2.0 charset-normalizer==3.4.4 chromadb==1.2.1 cleanlab==2.6.5 cleanlab-tlm==1.1.36 cleanvision==0.3.6 click==8.2.1 click-didyoumean==0.3.1 click-plugins==1.1.1.2 click-repl==0.3.0 cloudpathlib==0.23.0 colorama==0.4.6 coloredlogs==15.0.1 comm==0.2.3 confection==0.1.5 configurable-http-proxy==0.4.0 confusable-homoglyphs==3.3.1 confusables==1.2.0 contourpy==1.3.3 cramjam==2.11.0 cryptography==46.0.3 cycler==0.12.1 cymem==2.0.11 dataclasses-json==0.6.7 datasets==4.2.0 debugpy==1.8.17 decorator==5.2.1 deepeval==3.3.9 defusedxml==0.7.1 detoxify==0.5.2 dill==0.4.0 diskcache==5.6.3 distro==1.9.0 dnspython==2.8.0 docstring_parser==0.17.0 docxcompose==1.4.0 docxtpl==0.20.1 duckdb==1.4.1 duckdb_engine==0.17.0 duckduckgo_search==8.1.1 durationpy==0.10 dynaconf==3.2.12 email-validator==2.3.0 et_xmlfile==2.0.0 execnet==2.1.1 executing==2.2.1 fastapi==0.119.1 fastapi-cli==0.0.14 fastapi-cloud-cli==0.3.1 fastjsonschema==2.21.2 fastparquet==2024.11.0 filelock==3.20.0 filetype==1.2.0 Flask==3.1.2 flatbuffers==25.9.23 fonttools==4.60.1 fpdf2==2.8.4 fqdn==1.5.1 frozendict==2.4.6 frozenlist==1.8.0 fs==2.4.16 fsspec==2025.9.0 gast==0.6.0 genguardx==2025.10.24+g7487a6712 get-annotations==0.1.2 google-ai-generativelanguage==0.9.0 google-api-core==2.27.0 google-auth==2.41.1 google-cloud-dialogflow-cx==2.0.0 google-cloud-modelarmor==0.3.0 google-genai==1.46.0 google-pasta==0.2.0 googleapis-common-protos==1.71.0 greenlet==3.2.4 grpcio==1.76.0 grpcio-status==1.76.0 guidance==0.3.0 guidance-stitch==0.1.5 gunicorn==23.0.0 h11==0.16.0 h2==4.3.0 h2o==3.46.0.8 h5py==3.15.1 hf-xet==1.1.10 hpack==4.1.0 httpcore==1.0.9 httptools==0.7.1 httpx==0.28.1 httpx-sse==0.4.3 huggingface-hub==0.35.3 humanfriendly==10.0 hyperframe==6.1.0 idna==3.11 ImageHash==4.3.2 importlib_metadata==8.7.0 importlib_resources==6.5.2 inflect==7.3.1 iniconfig==2.3.0 ipykernel==7.0.1 ipython==9.6.0 ipython_pygments_lexers==1.1.1 ipywidgets==8.1.7 isodate==0.7.2 isoduration==20.11.0 itsdangerous==2.2.0 jaraco.collections==5.1.0 jaraco.context==5.3.0 jaraco.functools==4.0.1 jaraco.text==3.12.1 jedi==0.19.2 Jinja2==3.1.6 jiter==0.11.1 jmespath==1.0.1 joblib==1.5.2 json5==0.12.1 json_repair==0.52.3 jsonpatch==1.33 jsonpointer==3.0.0 jsonschema==4.25.1 jsonschema-path==0.3.4 jsonschema-specifications==2025.9.1 jupyter-events==0.12.0 jupyter-lsp==2.3.0 jupyter_client==8.6.3 jupyter_core==5.9.1 jupyter_server==2.17.0 jupyter_server_proxy==4.4.0 jupyter_server_terminals==0.5.3 jupyter_vscode_proxy==0.6 jupyterhub==5.4.1 jupyterlab==4.4.10 jupyterlab_pygments==0.3.0 jupyterlab_server==2.28.0 jupyterlab_widgets==3.0.15 kaleido==0.2.1 keras==3.11.3 kiwisolver==1.4.9 kombu==5.5.4 kubernetes==33.1.0 langchain==1.0.2 langchain-classic==1.0.0 langchain-community==0.4 langchain-core==1.0.0 langchain-google-genai==3.0.0 langchain-openai==1.0.1 langchain-text-splitters==1.0.0 langcodes==3.5.0 langgraph==1.0.1 langgraph-checkpoint==3.0.0 langgraph-prebuilt==1.0.1 langgraph-sdk==0.2.9 langsmith==0.4.37 language_data==1.3.0 lark==1.3.0 lazy-object-proxy==1.12.0 libclang==18.1.1 llguidance==1.1.0 lockfile==0.12.2 lxml==6.0.2 Mako==1.3.10 marisa-trie==1.3.1 Markdown==3.9 markdown-it-py==4.0.0 MarkupSafe==3.0.3 marshmallow==3.22.0 marshmallow-sqlalchemy==1.0.0 matplotlib==3.10.7 matplotlib-inline==0.1.7 mdurl==0.1.2 mistune==3.1.4 ml_dtypes==0.5.3 mmh3==5.2.0 monotonic==1.6 more-itertools==10.3.0 mpmath==1.3.0 msal==1.34.0 msal-extensions==1.3.1 multidict==6.7.0 multiprocess==0.70.16 murmurhash==1.0.13 mypy_extensions==1.1.0 namex==0.1.0 nbclient==0.10.2 nbconvert==7.16.6 nbformat==5.10.4 nest-asyncio==1.6.0 networkx==3.5 nltk==3.9.2 notebook_shim==0.2.4 notifiers==1.3.6 numpy==2.2.6 oauthlib==3.3.1 ollama==0.6.0 onnxruntime==1.23.2 openai==2.6.0 openapi-schema-validator==0.6.3 openapi-spec-validator==0.7.2 openpyxl==3.1.5 opentelemetry-api==1.38.0 opentelemetry-exporter-otlp-proto-common==1.38.0 opentelemetry-exporter-otlp-proto-grpc==1.38.0 opentelemetry-proto==1.38.0 opentelemetry-sdk==1.38.0 opentelemetry-semantic-conventions==0.59b0 opt_einsum==3.4.0 optree==0.17.0 oracledb==3.4.0 orjson==3.11.3 ormsgpack==1.11.0 overrides==7.7.0 packaging==25.0 pamela==1.2.0 pandas==2.3.3 pandocfilters==1.5.1 parso==0.8.5 passlib==1.7.4 pathable==0.4.4 patsy==1.0.2 pexpect==4.9.0 pillow==12.0.0 pip==25.3 platformdirs==4.5.0 plotly==5.24.1 pluggy==1.6.0 portalocker==3.2.0 posthog==3.25.0 prance==25.4.8.0 preshed==3.0.10 primp==0.15.0 prometheus_client==0.23.1 prompt_toolkit==3.0.52 propcache==0.4.1 proto-plus==1.26.1 protobuf==6.33.0 psutil==7.1.1 psycopg2-binary==2.9.11 ptyprocess==0.7.0 pure_eval==0.2.3 py-openapi-schema-to-json-schema==0.0.3 py4j==0.10.9.7 pyarrow==21.0.0 pyasn1==0.6.1 pyasn1_modules==0.4.2 pybase64==1.4.2 pycodestyle==2.14.0 pycountry==24.6.1 pycparser==2.23 pydantic==2.12.3 pydantic-settings==2.11.0 pydantic_core==2.41.4 pyfiglet==1.0.4 Pygments==2.19.2 PyJWT==2.10.1 pyodbc==5.3.0 pyotp==2.9.0 pyparsing==3.2.5 pypdf==6.1.3 PyPDF2==3.0.1 PyPika==0.48.9 pyproject_hooks==1.2.0 pyrit==0.9.0 pyspark==3.5.7 pysqlite3-binary==0.5.4 pytest==8.4.2 pytest-asyncio==1.2.0 pytest-repeat==0.9.4 pytest-rerunfailures==12.0 pytest-xdist==3.8.0 python-daemon==3.1.2 python-dateutil==2.9.0.post0 python-docx==1.2.0 python-dotenv==1.1.1 python-json-logger==4.0.0 python-magic==0.4.27 python-multipart==0.0.20 python3-saml==1.16.0 pytz==2025.2 PyWavelets==1.9.0 PyYAML==6.0.3 pyzmq==27.1.0 questionary==2.1.1 ragas==0.3.1 RapidFuzz==3.14.1 redis==5.2.1 referencing==0.36.2 regex==2025.10.23 requests==2.32.5 requests-oauthlib==2.0.0 requests-toolbelt==1.0.0 rfc3339-validator==0.1.4 rfc3986-validator==0.1.1 rfc3987-syntax==1.1.0 rich==14.2.0 rich-toolkit==0.15.1 rignore==0.7.1 rpds-py==0.28.0 rsa==4.9.1 ruamel.yaml==0.18.16 ruamel.yaml.clib==0.2.14 s3transfer==0.14.0 safetensors==0.6.2 scikit-learn==1.7.2 scipy==1.16.2 seaborn==0.13.2 secure==0.3.0 segno==1.6.6 semver==2.13.0 Send2Trash==1.8.3 sentence-transformers==5.1.2 sentencepiece==0.2.1 sentry-sdk==2.42.1 setproctitle==1.3.7 setuptools==80.9.0 shellingham==1.5.4 simpervisor==1.0.0 six==1.17.0 smart_open==7.4.1 sniffio==1.3.1 soupsieve==2.8 spacy==3.8.7 spacy-legacy==3.0.12 spacy-loggers==1.0.5 SQLAlchemy==2.0.44 sqlalchemy-history==2.1.4 SQLAlchemy-Utils==0.42.0 srsly==2.5.1 stack-data==0.6.3 starlette==0.48.0 statsmodels==0.14.5 stringcase==1.2.0 sympy==1.14.0 tabulate==0.9.0 tenacity==9.1.2 tensorboard==2.20.0 tensorboard-data-server==0.7.2 tensorflow==2.20.0 termcolor==3.1.0 terminado==0.18.1 tf_keras==2.20.1 thinc==8.3.6 threadpoolctl==3.6.0 tiktoken==0.12.0 tinycss2==1.4.0 tinytag==2.1.2 tokenizers==0.22.1 toml==0.10.2 tomli==2.0.1 torch==2.8.0+cpu tornado==6.5.2 tqdm==4.67.1 traitlets==5.14.3 transformers==4.57.1 treelib==1.8.0 typeguard==4.3.0 typer==0.20.0 typing-inspect==0.9.0 typing-inspection==0.4.2 typing_extensions==4.15.0 tzdata==2025.2 uri-template==1.3.0 urllib3==2.5.0 uvicorn==0.38.0 uvloop==0.22.1 vine==5.1.0 wasabi==1.1.3 watchfiles==1.1.1 wcwidth==0.2.14 weasel==0.4.1 webargs==8.7.0 webcolors==24.11.1 webencodings==0.5.1 websocket-client==1.9.0 websockets==15.0.1 Werkzeug==3.1.3 wheel==0.45.1 widgetsnbextension==4.0.14 wrapt==2.0.0 xmlsec==1.3.16 xxhash==3.6.0 yarl==1.22.0 zipp==3.23.0 zstandard==0.25.0

Additional context

No response

rajneesh407 avatar Nov 14 '25 17:11 rajneesh407