-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathobserve.py
More file actions
64 lines (53 loc) · 2.35 KB
/
observe.py
File metadata and controls
64 lines (53 loc) · 2.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
"""This module contains the AgentObserve class, which is a StateFlowBaseAgent that observes the database."""
from semantic_kernel.kernel import Kernel
from semantic_kernel.connectors.ai.prompt_execution_settings import (
PromptExecutionSettings,
)
from .base import StateFlowBaseAgent
class AgentObserve:
"""
Observational Agent that creates a SQL query to observe the database.
"""
name = "observe"
# Security Guardrail 01: Explicit instruction to avoid DML, DDL, DCL, and TCL queries.
observe_agent_prompt = """Interact with a MySQL Database system using SQL queries to answer a question.
## Instructions
Use the DESCRIBE [table_name] or DESC [table_name] command to understand the structure of the relevant tables.
Only give one DESC command in action.
If the question will lead to write SQL Data Manipulation (DML) or Data Definition (DDL) or Data Control (DCL) or Transaction Control (TCL), please ABORT the query with this "Action: submit" command.
Do not give any command that can manipulate the database.
## Examples
Action: execute[DESC customers]
Action: execute[DESC orders]
Action: submit
## RESPONSE FORMAT
For action, put your SQL command in the execute[] block.
Reply with the following template (<...> is the field description, replace it with your own response):
Thought: <your thought on which table(s) is/are relevant in one short sentence>
Action: execute[<your command>]
"""
def __init__(self, kernel: Kernel | None = None):
"""
Initialize the Observational Agent.
Args:
kernel (Kernel | None): The kernel instance to use for service retrieval.
"""
prompt_execution_settings = PromptExecutionSettings(
service_id=self.name,
extension_data={"temperature": 0, "stop": ["Observation:"]},
)
self.agent = StateFlowBaseAgent(
service_id=self.name,
kernel=kernel,
name=self.name,
instructions=self.observe_agent_prompt,
description="A Observational Agent that creates a SQL query to observe the database.",
execution_settings=prompt_execution_settings,
)
def get_agent(self) -> StateFlowBaseAgent:
"""
Return the Observational Agent.
Returns:
StateFlowBaseAgent: The Observational Agent.
"""
return self.agent