/ examples / exp_pool / manager.py
manager.py
 1  """
 2  Demonstrate the creation and querying of experiences.
 3  
 4  This script creates a new experience, logs its creation, and then queries for experiences matching the same request.
 5  """
 6  
 7  import asyncio
 8  
 9  from metagpt.exp_pool import get_exp_manager
10  from metagpt.exp_pool.schema import EntryType, Experience
11  from metagpt.logs import logger
12  
13  
14  async def main():
15      # Define the simple request and response
16      req = "Simple req"
17      resp = "Simple resp"
18  
19      # Add the new experience
20      exp = Experience(req=req, resp=resp, entry_type=EntryType.MANUAL)
21      exp_manager = get_exp_manager()
22      exp_manager.create_exp(exp)
23      logger.info(f"New experience created for the request `{req}`.")
24  
25      # Query for experiences matching the request
26      exps = await exp_manager.query_exps(req)
27      logger.info(f"Got experiences: {exps}")
28  
29  
30  if __name__ == "__main__":
31      asyncio.run(main())