fix(agent): pass user_id in agent invocation for enhanced context
Browse files- api/routers/chats.py +1 -1
- db/schemas/message.py +6 -2
api/routers/chats.py
CHANGED
@@ -111,7 +111,7 @@ async def post_message_and_get_response(
|
|
111 |
initial_message_count = len(messages_for_agent)
|
112 |
|
113 |
# 4. Invoke the agent
|
114 |
-
response = await agent.ainvoke(messages_for_agent)
|
115 |
|
116 |
# 5. Extract results from the agent's structured output
|
117 |
final_answer = response["answer"]
|
|
|
111 |
initial_message_count = len(messages_for_agent)
|
112 |
|
113 |
# 4. Invoke the agent
|
114 |
+
response = await agent.ainvoke(messages_for_agent, config={"configurable": {"user_id": str(user_id)}})
|
115 |
|
116 |
# 5. Extract results from the agent's structured output
|
117 |
final_answer = response["answer"]
|
db/schemas/message.py
CHANGED
@@ -19,11 +19,15 @@ class MessageRead(BaseModel):
|
|
19 |
|
20 |
links: Optional[list[HttpUrl]] = None
|
21 |
|
|
|
|
|
|
|
|
|
|
|
22 |
@computed_field
|
23 |
@property
|
24 |
def content(self) -> str:
|
25 |
-
|
26 |
-
return self.answer
|
27 |
|
28 |
class Config:
|
29 |
from_attributes = True
|
|
|
19 |
|
20 |
links: Optional[list[HttpUrl]] = None
|
21 |
|
22 |
+
raw_content: Optional[str] = Field(None, alias='content', exclude=True)
|
23 |
+
answer: Optional[str] = Field(None, alias='answer', exclude=True)
|
24 |
+
|
25 |
+
# Step 2: The computed field now accesses the private, guaranteed-to-exist attributes
|
26 |
+
# on the MessageRead instance itself.
|
27 |
@computed_field
|
28 |
@property
|
29 |
def content(self) -> str:
|
30 |
+
return self.answer if self.answer is not None else self.raw_content
|
|
|
31 |
|
32 |
class Config:
|
33 |
from_attributes = True
|