From c3cf9a9c764e571f131ce5470729e574d480c98d Mon Sep 17 00:00:00 2001 From: James Ketrenos Date: Tue, 29 Apr 2025 16:04:43 -0700 Subject: [PATCH] Almost working? --- src/server.py | 4 +++- src/utils/agents/chat.py | 26 ++------------------------ src/utils/context.py | 3 +-- 3 files changed, 6 insertions(+), 27 deletions(-) diff --git a/src/server.py b/src/server.py index df0a7ce..d1cfa19 100644 --- a/src/server.py +++ b/src/server.py @@ -648,7 +648,6 @@ class WebServer: return JSONResponse({"error": "Invalid context_id"}, status_code=400) context = self.upsert_context(context_id) - try: data = await request.json() agent = context.get_agent(agent_type) @@ -978,6 +977,9 @@ class WebServer: async def generate_response(self, context : Context, agent : Agent, content : str): if not self.file_watcher: return + + if agent.agent_type == "Chat": + agent.proces if self.processing: logging.info("TODO: Implement delay queing; busy for same agent, otherwise return queue size and estimated wait time") diff --git a/src/utils/agents/chat.py b/src/utils/agents/chat.py index 26b4618..14475e2 100644 --- a/src/utils/agents/chat.py +++ b/src/utils/agents/chat.py @@ -4,7 +4,7 @@ from typing_extensions import Annotated from abc import ABC, abstractmethod from typing_extensions import Annotated import logging -from .base import Agent, registry +from .base import Agent, ContextBase, registry from .. conversation import Conversation from .. message import Message @@ -16,32 +16,10 @@ class Chat(Agent, ABC): agent_type: Literal["chat"] = "chat" _agent_type: ClassVar[str] = agent_type # Add this for registration - def __init_subclass__(cls, **kwargs): - """Auto-register subclasses""" - super().__init_subclass__(**kwargs) - # Register this class if it has an agent_type - if hasattr(cls, 'agent_type') and cls.agent_type != Agent.agent_type: - registry.register(cls.agent_type, cls) - - def __init__(self, **data): - # Set agent_type from class if not provided - if 'agent_type' not in data: - data['agent_type'] = self.__class__.agent_type - super().__init__(**data) - system_prompt: str # Mandatory conversation: Conversation = Conversation() context_tokens: int = 0 - - # Add a property for context if needed without creating a circular reference - @property - def context(self) -> Optional['Context']: - if TYPE_CHECKING: - from .context import Context - # Implement logic to fetch context by ID if needed - return None - - #context: Context + context: ContextBase _content_seed: str = PrivateAttr(default="") diff --git a/src/utils/context.py b/src/utils/context.py index 4afe65a..ecd4d8c 100644 --- a/src/utils/context.py +++ b/src/utils/context.py @@ -135,10 +135,9 @@ class Context(ContextBase): # Find the matching subclass for agent_cls in Agent.__subclasses__(): - logging.info(f"Found class: {agent_cls.model_fields['agent_type'].default}") if agent_cls.model_fields["agent_type"].default == agent_type: # Create the agent instance with provided kwargs - agent = agent_cls(agent_type=agent_type, **kwargs) + agent = agent_cls(agent_type=agent_type, context=self, **kwargs) self.agents.append(agent) return agent