From 33db023e9448e06d7e3a7cbf8a7492990db44250 Mon Sep 17 00:00:00 2001 From: geekan Date: Tue, 9 Jan 2024 16:32:38 +0800 Subject: [PATCH] add context mixin --- metagpt/context.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/metagpt/context.py b/metagpt/context.py index eb46ab19b..293beb9b5 100644 --- a/metagpt/context.py +++ b/metagpt/context.py @@ -103,5 +103,23 @@ class Context(LLMMixin, BaseModel): # return llm +class ContextMixin: + """Mixin class for configurable objects""" + + _context: Optional[Context] = None + + def __init__(self, context: Optional[Context] = None): + self._context = context + + def set_context(self, context: Optional[Context] = None): + """Set parent context""" + self._context = context + + @property + def context(self): + """Get config""" + return self._context + + # Global context, not in Env context = Context()