|
|
@@ -702,7 +702,7 @@ class ContextAwareAgent(SimpleAgent):
|
|
|
"""具有上下文感知能力的 Agent"""
|
|
|
|
|
|
def __init__(self, name: str, llm: HelloAgentsLLM, **kwargs):
|
|
|
- super().__init__(name=name, llm=llm, **kwargs)
|
|
|
+ super().__init__(name=name, llm=llm, system_prompt=kwargs.get("system_prompt", ""))
|
|
|
|
|
|
# 初始化上下文构建器
|
|
|
self.memory_tool = MemoryTool(user_id=kwargs.get("user_id", "default"))
|
|
|
@@ -727,6 +727,10 @@ class ContextAwareAgent(SimpleAgent):
|
|
|
)
|
|
|
|
|
|
# 2. 使用优化后的上下文调用 LLM
|
|
|
+ messages = [
|
|
|
+ {"role": "system", "content": optimized_context},
|
|
|
+ {"role": "user", "content": user_input}
|
|
|
+ ]
|
|
|
response = self.llm.invoke(optimized_context)
|
|
|
|
|
|
# 3. 更新对话历史
|
|
|
@@ -754,6 +758,7 @@ class ContextAwareAgent(SimpleAgent):
|
|
|
agent = ContextAwareAgent(
|
|
|
name="数据分析顾问",
|
|
|
llm=HelloAgentsLLM(),
|
|
|
+ system_prompt="你是一位资深的Python数据工程顾问。",
|
|
|
user_id="user123",
|
|
|
knowledge_base_path="./data_science_kb"
|
|
|
)
|