Extend use of user + collection fields (#503)

* Collection+user fields in structured query

* User/collection in structured query & agent
This commit is contained in:
cybermaggedon 2025-09-08 18:28:38 +01:00 committed by GitHub
parent a92050c411
commit f22bf13aa6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
15 changed files with 122 additions and 45 deletions

View file

@ -132,11 +132,15 @@ class FlowInstance:
input
)["response"]
def agent(self, question):
def agent(self, question, user="trustgraph", state="", group=None, history=None):
# The input consists of a question
# The input consists of a question and optional context
input = {
"question": question
"question": question,
"user": user,
"state": state,
"group": group or [],
"history": history or []
}
return self.request(
@ -456,20 +460,24 @@ class FlowInstance:
return response
def structured_query(self, question):
def structured_query(self, question, user="trustgraph", collection="default"):
"""
Execute a natural language question against structured data.
Combines NLP query conversion and GraphQL execution.
Args:
question: Natural language question
user: Cassandra keyspace identifier (default: "trustgraph")
collection: Data collection identifier (default: "default")
Returns:
dict with data and optional errors
"""
input = {
"question": question
"question": question,
"user": user,
"collection": collection
}
response = self.request(

View file

@ -2,10 +2,12 @@ from . request_response_spec import RequestResponse, RequestResponseSpec
from .. schema import StructuredQueryRequest, StructuredQueryResponse
class StructuredQueryClient(RequestResponse):
async def structured_query(self, question, timeout=600):
async def structured_query(self, question, user="trustgraph", collection="default", timeout=600):
resp = await self.request(
StructuredQueryRequest(
question = question
question = question,
user = user,
collection = collection
),
timeout=timeout
)

View file

@ -9,17 +9,19 @@ class AgentRequestTranslator(MessageTranslator):
def to_pulsar(self, data: Dict[str, Any]) -> AgentRequest:
return AgentRequest(
question=data["question"],
plan=data.get("plan", ""),
state=data.get("state", ""),
history=data.get("history", [])
group=data.get("group", []),
history=data.get("history", []),
user=data.get("user", "trustgraph")
)
def from_pulsar(self, obj: AgentRequest) -> Dict[str, Any]:
return {
"question": obj.question,
"plan": obj.plan,
"state": obj.state,
"history": obj.history
"group": obj.group,
"history": obj.history,
"user": obj.user
}

View file

@ -9,12 +9,16 @@ class StructuredQueryRequestTranslator(MessageTranslator):
def to_pulsar(self, data: Dict[str, Any]) -> StructuredQueryRequest:
return StructuredQueryRequest(
question=data.get("question", "")
question=data.get("question", ""),
user=data.get("user", "trustgraph"), # Default fallback
collection=data.get("collection", "default") # Default fallback
)
def from_pulsar(self, obj: StructuredQueryRequest) -> Dict[str, Any]:
return {
"question": obj.question
"question": obj.question,
"user": obj.user,
"collection": obj.collection
}

View file

@ -13,12 +13,14 @@ class AgentStep(Record):
action = String()
arguments = Map(String())
observation = String()
user = String() # User context for the step
class AgentRequest(Record):
question = String()
state = String()
group = Array(String())
history = Array(AgentStep())
user = String() # User context for multi-tenancy
class AgentResponse(Record):
answer = String()

View file

@ -9,6 +9,8 @@ from ..core.topic import topic
class StructuredQueryRequest(Record):
question = String()
user = String() # Cassandra keyspace identifier
collection = String() # Data collection identifier
class StructuredQueryResponse(Record):
error = Error()