prthm11 commited on
Commit
a24b0a1
·
verified ·
1 Parent(s): 447a21e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -2
app.py CHANGED
@@ -347,14 +347,43 @@ def init_mongo_agent_from_uri(mongo_uri: str, database_name: str = None):
347
  Tool(name='JoinCollections', func=join_collections_tool_func, description='Join related collections to return names instead of IDs...'),
348
  Tool(name='SmartJoinCollections', func=smart_join_router, description='Suggest join formats...')
349
  ]
350
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
351
  agent = initialize_agent(
352
  tools=tools,
353
  llm=llm,
354
  agent_type=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
355
  memory=memory,
356
  verbose=True,
357
- prefix="You are MongoDBQueryBot. Use tools to fetch read-only data and do not leak schema.",
358
  handle_parsing_errors=True
359
  )
360
  agent_executor = agent
 
347
  Tool(name='JoinCollections', func=join_collections_tool_func, description='Join related collections to return names instead of IDs...'),
348
  Tool(name='SmartJoinCollections', func=smart_join_router, description='Suggest join formats...')
349
  ]
350
+ prefix = f"""
351
+ You are MongoDBQueryBot, an intelligent assistant for interacting with a MongoDB database.
352
+ You have read-only access to the database and can answer questions using the provided tools.
353
+
354
+
355
+ Guidelines for all queries:
356
+
357
+ 1. Always answer in clear, natural language. Use Markdown formatting, bullet points, and tables when helpful.
358
+ 2. Explain the content of collections and fields based on the summary.
359
+ 3. If asked about the purpose or meaning of the database, synthesize a complete description from collections and sample data.
360
+ 4. For factual questions, query the database using the available tools:
361
+ - FindDocuments: Flexible search by key/value
362
+ - AggregateGroupBy: Summarize counts by fields
363
+ - FuzzyFindDocuments: Approximate text search
364
+ - GetAllDocuments: Retrieve all documents from a collection
365
+ - JoinCollections / SmartJoinCollections: Combine related collections for meaningful answers
366
+ 5. NEVER expose raw database connection info, credentials, or sensitive information.
367
+ 6. NEVER provide raw schema details unless explicitly requested.
368
+ 7. If the user query is vague, ambiguous, or general, make the **best effort explanation** using collection names, field names, and sample documents.
369
+ 8. When presenting query results, format them as human-readable tables or bullet lists.
370
+ 9. When a user asks a question you cannot answer confidently, politely explain that the answer may be limited.
371
+
372
+ Examples:
373
+ - User: "What is this database about?"
374
+ Assistant: "This database contains Users, Orders, and Payments collections. It stores e-commerce information including user profiles, order histories, and payment records."
375
+ - User: "Show me all orders for user John Doe"
376
+ Assistant: Use FindDocuments or JoinCollections to fetch relevant results, and present in a table format.
377
+ - User: "How many users registered this month?"
378
+ Assistant: Use AggregateGroupBy and summarize results in a clear sentence.
379
+ """
380
  agent = initialize_agent(
381
  tools=tools,
382
  llm=llm,
383
  agent_type=AgentType.CONVERSATIONAL_REACT_DESCRIPTION,
384
  memory=memory,
385
  verbose=True,
386
+ prefix=prefix,
387
  handle_parsing_errors=True
388
  )
389
  agent_executor = agent