Skip to content

Conversation

pradanaadn
Copy link

@pradanaadn pradanaadn commented Jul 7, 2025

  • Update the agent_toolkit prompt for the query checker to ensure it return pymongo syntax.

It keep return query in json:

================================= Tool Message =================================
Name: mongodb_query_checker

content='json\n{\n aggregate: "sales",\n pipeline: [\n { $unwind: "$items" },\n { $unwind: "$items.tags" },\n {\n $group: {\n _id: "$items.tags",\n totalSales: { $sum: { $multiply: ["$items.price", "$items.quantity"] } }\n }\n },\n { $sort: { totalSales: -1 } },\n { $limit: 5 }\n ]\n}\n\n\n### Explanation:\n1. Unwinding Tags: The tags field within items is likely an array, which requires an additional $unwind stage to flatten the array and properly group by individual tags.\n2. Identifiers and Operators Quoting: The identifiers and operators are quoted correctly in the original query, and there are no syntax errors related to quoting.\n3. JSON Validity: The query is valid JSON format as part of a MongoDB aggregation pipeline.\n\nThe main change is the addition of an extra $unwind stage for items.tags. This ensures the query groups by each individual tag rather than the array of tags.' additional_kwargs={'refusal': None} response_metadata={'token_usage': {'completion_tokens': 239, 'prompt_tokens': 178, 'total_tokens': 417, 'completion_tokens_details': {'accepted_prediction_tokens': 0, 'audio_tokens': 0, 'reasoning_tokens': 0, 'rejected_prediction_tokens': 0}, 'prompt_tokens_details': {'audio_tokens': 0, 'cached_tokens': 0}}, 'model_name': 'gpt-4o-2024-08-06', 'system_fingerprint': 'fp_a288987b44', 'id': 'chatcmpl-BqWxt1ajfavqmGTBS06BLsuDhCM1D', 'service_tier': 'default', 'finish_reason': 'stop', 'logprobs': None} id='run--75a8df8b-cf4e-4e79-aba0-dcea8b9c8e69-0' usage_metadata={'input_tokens': 178, 'output_tokens': 239, 'total_tokens': 417, 'input_token_details': {'audio': 0, 'cache_read': 0}, 'output_token_details': {'audio': 0, 'reasoning': 0}}

Copy link
Collaborator

@blink1073 blink1073 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I just have one comment

@@ -34,17 +34,25 @@
MONGODB_FUNCTIONS_SUFFIX = """I should look at the collections in the database to see what I can query. Then I should query the schema of the most relevant collections."""


MONGODB_QUERY_CHECKER = """
MONGODB_QUERY_CHECKER = MONGODB_QUERY_CHECKER = """
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was this change unintentional?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants