Almost working?

This commit is contained in:
James Ketr 2025-04-29 17:46:10 -07:00
parent 622c33545e
commit 4614dbb237
5 changed files with 61 additions and 5 deletions

View File

@ -293,7 +293,7 @@ RUN { \
echo ' openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout src/key.pem -out src/cert.pem -subj "/C=US/ST=OR/L=Portland/O=Development/CN=localhost"'; \ echo ' openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout src/key.pem -out src/cert.pem -subj "/C=US/ST=OR/L=Portland/O=Development/CN=localhost"'; \
echo ' fi' ; \ echo ' fi' ; \
echo ' while true; do'; \ echo ' while true; do'; \
echo ' if [[ ! -e /opt/backstory/block-server ]]; then' \ echo ' if [[ ! -e /opt/backstory/block-server ]]; then'; \
echo ' echo "Launching Backstory server..."'; \ echo ' echo "Launching Backstory server..."'; \
echo ' python src/server.py "${@}" || echo "Backstory server died."'; \ echo ' python src/server.py "${@}" || echo "Backstory server died."'; \
echo ' else'; \ echo ' else'; \

View File

@ -1,3 +1,6 @@
import warnings
warnings.filterwarnings("ignore", message="Overriding a previously registered kernel")
# %% # %%
# Imports [standard] # Imports [standard]
# Standard library modules (no try-except needed) # Standard library modules (no try-except needed)

View File

@ -1,9 +1,12 @@
from typing import Optional, Type
from . import defines from . import defines
from .rag import ChromaDBFileWatcher, start_file_watcher from .rag import ChromaDBFileWatcher, start_file_watcher
from .message import Message from .message import Message
from .conversation import Conversation from .conversation import Conversation
from .context import Context from .context import Context
from . import agents from . import agents
import logging
from .agents import Agent, __all__ as agents_all from .agents import Agent, __all__ as agents_all
@ -14,4 +17,47 @@ __all__ = [
'Message', 'Message',
'ChromaDBFileWatcher', 'ChromaDBFileWatcher',
'start_file_watcher' 'start_file_watcher'
] + agents_all ] + agents_all
# Resolve circular dependencies by rebuilding models
# Call model_rebuild() on Agent and Context
Agent.model_rebuild()
Context.model_rebuild()
import logging
import importlib
from pydantic import BaseModel
from typing import Type
# Assuming class_registry is available from agents/__init__.py
from .agents import class_registry, AnyAgent
def rebuild_models():
Context.model_rebuild()
for class_name, (module_name, _) in class_registry.items():
try:
module = importlib.import_module(module_name)
cls = getattr(module, class_name, None)
logging.info(f"Checking: {class_name} in module {module_name}")
logging.info(f" cls: {True if cls else False}")
logging.info(f" isinstance(cls, type): {isinstance(cls, type)}")
logging.info(f" issubclass(cls, BaseModel): {issubclass(cls, BaseModel) if cls else False}")
logging.info(f" issubclass(cls, AnyAgent): {issubclass(cls, AnyAgent) if cls else False}")
logging.info(f" cls is not AnyAgent: {cls is not AnyAgent if cls else True}")
if (
cls
and isinstance(cls, type)
and issubclass(cls, BaseModel)
and issubclass(cls, AnyAgent)
and cls is not AnyAgent
):
logging.info(f"Rebuilding {class_name} from {module_name}")
cls.model_rebuild()
except ImportError as e:
logging.error(f"Failed to import module {module_name}: {e}")
except Exception as e:
logging.error(f"Error processing {class_name} in {module_name}: {e}")
# Call this after all modules are imported
rebuild_models()

View File

@ -1,5 +1,5 @@
from pydantic import BaseModel, Field, model_validator, PrivateAttr from pydantic import BaseModel, Field, model_validator, PrivateAttr
from typing import Literal, TypeAlias, get_args, List, Generator, Iterator, AsyncGenerator, TYPE_CHECKING, Optional, ClassVar from typing import Literal, TypeAlias, get_args, List, Generator, Iterator, AsyncGenerator, TYPE_CHECKING, Optional, ClassVar, ForwardRef
from abc import ABC, abstractmethod from abc import ABC, abstractmethod
from typing_extensions import Annotated from typing_extensions import Annotated
import logging import logging
@ -8,7 +8,9 @@ import logging
if TYPE_CHECKING: if TYPE_CHECKING:
from .. context import Context from .. context import Context
from .types import AgentBase, ContextRef, registry ContextRef = ForwardRef('Context')
from .types import AgentBase, registry
from .. conversation import Conversation from .. conversation import Conversation
from .. message import Message from .. message import Message
@ -41,6 +43,9 @@ class Agent(AgentBase):
# Set agent_type from class if not provided # Set agent_type from class if not provided
if 'agent_type' not in data: if 'agent_type' not in data:
data['agent_type'] = self.__class__.agent_type data['agent_type'] = self.__class__.agent_type
from .. context import Context
Context.model_rebuild()
self.__class__.model_rebuild()
super().__init__(**data) super().__init__(**data)
def get_agent_type(self): def get_agent_type(self):

View File

@ -176,4 +176,6 @@ class Context(BaseModel):
summary += f"\nFacts: {agent.facts}\n" summary += f"\nFacts: {agent.facts}\n"
elif agent.agent_type == "chat": elif agent.agent_type == "chat":
summary += f"\nChat Name: {agent.name}\n" summary += f"\nChat Name: {agent.name}\n"
return summary return summary
Context.model_rebuild()