From 1048bc145cd0341fcbdd269f3275079bc40ede70 Mon Sep 17 00:00:00 2001 From: batsumaru <> Date: Fri, 11 Sep 2026 13:56:07 +0900 Subject: Added llm logic and config --- agent.py | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 agent.py (limited to 'agent.py') diff --git a/agent.py b/agent.py new file mode 100644 index 0000000..51661fd --- /dev/null +++ b/agent.py @@ -0,0 +1,45 @@ +from collections.abc import Iterator + +from context import ContextBuilder +from identity import AgentIdentity, UserProfile +from llm import LLM + +class Agent: + def __init__( + self, + llm: LLM, + agent_identity: AgentIdentity, + user_profile: UserProfile + ) -> None: + self.llm = llm + + self.context = ContextBuilder( + agent_identity, + user_profile, + ) + + self.messages: list[dict[str, str]] = [ + { + "role": "system", + "content": self.context.build_system_prompt(), + } + ] + + def chat(self, user_input: str) -> Iterator[str]: + self.messages.append({ + "role": "user", + "content": user_input, + }) + + answer_parts: list[str] = [] + + for chunk in self.llm.chat(self.messages): + yield chunk + answer_parts.append(chunk) + + answer = "".join(answer_parts) + + self.messages.append({ + "role": "assistant", + "content": answer, + }) -- cgit v1.3