mirror of
https://github.com/agentscope-ai/ReMe.git
synced 2026-10-06 02:48:22 +00:00
update react demo
This commit is contained in:
parent
c55ad1fd76
commit
59a5b53a92
5 changed files with 35 additions and 105 deletions
30
cookbook/simple_agent/experience.jsonl
Normal file
30
cookbook/simple_agent/experience.jsonl
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
[
|
||||
{
|
||||
"workspace_id": "test_workspace1",
|
||||
"experience_id": "e249d97f56dd452badd764a81dc22709",
|
||||
"experience_type": "text",
|
||||
"when_to_use": "When analyzing a large, multifaceted corporation across various dimensions such as financials, market position, and technological innovations.",
|
||||
"content": "Breaking down the problem into smaller subtasks (e.g., financial performance, market standing, recent developments) allows for a more systematic and comprehensive analysis. Using multiple `web_search` calls with specific queries ensures that each dimension is thoroughly covered from different angles.",
|
||||
"score": null,
|
||||
"metadata": {
|
||||
"author": "qwen-max-2025-01-25",
|
||||
"created_time": "2025-07-21 16:35:35",
|
||||
"modified_time": "2025-07-21 16:35:35",
|
||||
"extra_info": null
|
||||
}
|
||||
},
|
||||
{
|
||||
"workspace_id": "test_workspace1",
|
||||
"experience_id": "c13abd248d1a48e89582f0177a7a0f84",
|
||||
"experience_type": "text",
|
||||
"when_to_use": "When information retrieved seems sufficient but fragmented across several sources and needs to be synthesized into a coherent response.",
|
||||
"content": "After gathering data through various tool calls, it is crucial to integrate all relevant pieces of information into a unified narrative. This involves cross-referencing the content, ensuring consistency, and presenting the findings in a structured manner so that the final output directly addresses the user’s question without leaving gaps or introducing redundancies.",
|
||||
"score": null,
|
||||
"metadata": {
|
||||
"author": "qwen-max-2025-01-25",
|
||||
"created_time": "2025-07-21 16:35:35",
|
||||
"modified_time": "2025-07-21 16:35:35",
|
||||
"extra_info": null
|
||||
}
|
||||
}
|
||||
]
|
||||
|
|
@ -5,11 +5,10 @@ from dotenv import load_dotenv
|
|||
|
||||
load_dotenv()
|
||||
base_url = "http://0.0.0.0:8001/"
|
||||
workspace_id = "test_workspace"
|
||||
workspace_id = "test_workspace1"
|
||||
|
||||
|
||||
def run_agent(query: str, dump_messages: bool = False):
|
||||
query = "Analyze Xiaomi Corporation"
|
||||
|
||||
response = requests.post(url=base_url + "agent", json={"query": query})
|
||||
if response.status_code != 200:
|
||||
|
|
@ -30,7 +29,7 @@ def run_agent(query: str, dump_messages: bool = False):
|
|||
|
||||
|
||||
def run_summary(messages: list, dump_experience: bool = True):
|
||||
response = requests.post(url=base_url + "summary", json={
|
||||
response = requests.post(url=base_url + "summarizer", json={
|
||||
"workspace_id": workspace_id,
|
||||
"traj_list": [
|
||||
{"messages": messages, "score": 1.0}
|
||||
|
|
@ -65,8 +64,8 @@ def run_retriever(query: str):
|
|||
|
||||
|
||||
def run_agent_with_experience(query_first: str, query_second: str, dump_experience: bool = True):
|
||||
messages = run_agent(query=query_second)
|
||||
run_summary(messages, dump_experience)
|
||||
# messages = run_agent(query=query_second)
|
||||
# run_summary(messages, dump_experience)
|
||||
experience_merged = run_retriever(query_first)
|
||||
messages = run_agent(query=f"{experience_merged}\n\nUser Question:\n{query_first}")
|
||||
return messages
|
||||
|
|
|
|||
|
|
@ -1,70 +0,0 @@
|
|||
from loguru import logger
|
||||
from pydantic import Field, model_validator
|
||||
|
||||
from cookbook.simple_agent.your_own_agent import YourOwnAgent
|
||||
from experiencemaker.em_client import EMClient
|
||||
from experiencemaker.schema.request import ContextGeneratorRequest, SummarizerRequest
|
||||
from experiencemaker.schema.response import ContextGeneratorResponse, SummarizerResponse
|
||||
from experiencemaker.schema.trajectory import Trajectory
|
||||
|
||||
|
||||
class YourOwnAgentEnhanced(YourOwnAgent):
|
||||
em_client: EMClient | None = Field(default=None)
|
||||
workspace_id: str = Field(default=...)
|
||||
|
||||
@model_validator(mode="after")
|
||||
def init_client(self):
|
||||
self.em_client = EMClient(base_url="http://0.0.0.0:8001")
|
||||
return self
|
||||
|
||||
def summary_experience(self, query: str):
|
||||
messages = self.run(query)
|
||||
trajectory: Trajectory = Trajectory(query=query, steps=messages, answer=messages[-1].content, is_terminated=True)
|
||||
|
||||
request: SummarizerRequest = SummarizerRequest(trajectories=[trajectory], workspace_id=self.workspace_id)
|
||||
response: SummarizerResponse = self.em_client.call_summarizer(request)
|
||||
for experience in response.experiences:
|
||||
logger.info(experience.model_dump_json())
|
||||
return response.experiences
|
||||
|
||||
def run_with_experience(self, query: str):
|
||||
trajectory: Trajectory = Trajectory(query=query)
|
||||
request: ContextGeneratorRequest = ContextGeneratorRequest(trajectory=trajectory,
|
||||
retrieve_top_k=1,
|
||||
workspace_id=self.workspace_id)
|
||||
response: ContextGeneratorResponse = self.em_client.call_context_generator(request)
|
||||
new_query = f"{response.context_msg.content}\n\nUser Question\n{query}"
|
||||
logger.info(f"new query={new_query}")
|
||||
messages = self.run(new_query)
|
||||
|
||||
trajectory.steps = messages
|
||||
trajectory.answer = messages[-1].content
|
||||
trajectory.is_terminated = True
|
||||
trajectory.metadata["experience"] = response.context_msg.content
|
||||
return trajectory
|
||||
|
||||
def execute(self):
|
||||
self.summary_experience(query="Analyze the company Tesla.")
|
||||
# self.summary_experience(query="Analyze the company Apple.")
|
||||
|
||||
return self.run_with_experience(query="Analyze Xiaomi Corporation.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# agent = YourOwnAgentEnhanced(workspace_id="w_agent_enhanced",
|
||||
# llm=OpenAICompatibleBaseLLM(model_name="qwen3-32b", temperature=0.00001))
|
||||
# traj = agent.execute()
|
||||
# logger.info(traj.model_dump_json(indent=2))
|
||||
|
||||
em_client = EMClient(base_url="http://0.0.0.0:8001")
|
||||
|
||||
|
||||
request: ContextGeneratorRequest = ContextGeneratorRequest(trajectory=Trajectory(query="hello"),
|
||||
workspace_id="w123")
|
||||
response = em_client.call_summarizer()
|
||||
print(response)
|
||||
|
||||
|
||||
request: ContextGeneratorRequest = ContextGeneratorRequest(trajectory=Trajectory(query="hello"), workspace_id="w123")
|
||||
response = em_client.call_context_generator(request=request)
|
||||
print(response)
|
||||
|
|
@ -1,27 +0,0 @@
|
|||
role_prompt: |
|
||||
You are a helpful assistant named BeyondAgent.
|
||||
The current time is {time}.
|
||||
|
||||
Please proactively choose the most suitable tool or combination of tools based on the user's question, including {tools} etc.
|
||||
For complex tasks, you can break down the problem step by step and use different tools to solve it incrementally.
|
||||
Please determine the response language based on the language of the user's question.
|
||||
|
||||
{query}
|
||||
|
||||
next_prompt: |
|
||||
User question
|
||||
{query}
|
||||
|
||||
Plan the most suitable tool or combination of tools based on the context and the user's question.
|
||||
For complex tasks, break down the problem and use different tools step by step to solve it, don't give up easily.
|
||||
Try calling the same tool multiple times with different parameters to obtain information from various perspectives.
|
||||
If the task is completed and the user's question can now be answered, use the **terminate** tool.
|
||||
Please determine the response language based on the language of the user's question.
|
||||
|
||||
final_prompt: |
|
||||
Please integrate the context and provide a complete answer to the user's question.
|
||||
Please determine the response language based on the language of the user's question.
|
||||
|
||||
User question
|
||||
{query}
|
||||
|
||||
|
|
@ -6,7 +6,6 @@ role_prompt: |
|
|||
Try calling the same tool multiple times with different parameters to obtain information from various perspectives.
|
||||
Please determine the response language based on the language of the user's question.
|
||||
|
||||
# User's Question
|
||||
{query}
|
||||
|
||||
# write a complete and rigorous report to answer user's questions based on the context.
|
||||
|
|
@ -19,11 +18,10 @@ next_prompt: |
|
|||
Please first provide the reasoning process, then give the tool call name and parameters.
|
||||
|
||||
- If the current context is sufficient to answer the user's question, use the **terminate** tool.
|
||||
Please determine the response language based on the language of the user's question.
|
||||
|
||||
# Please determine the response language based on the language of the user's question.
|
||||
final_prompt: |
|
||||
Please integrate the context and provide a complete answer to the user's question.
|
||||
Please determine the response language based on the language of the user's question.
|
||||
|
||||
# User's Question
|
||||
{query}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue