Overview
AgentSystem is the abstract base class that all agents in HyperAgents inherit from. It lives in agent/base_agent.py and provides two things every agent needs: a configured LLM model identifier and a thread-safe logger that writes conversation history to a markdown file.
Both MetaAgent and TaskAgent extend AgentSystem and implement its single abstract method, forward.
Source
agent/base_agent.py
Constructor
The LLM model identifier passed to LiteLLM. Uses the
provider/model-name format. The default constant OPENAI_MODEL resolves to
"openai/gpt-4o".Path to the file where the full conversation history (all LLM inputs and
outputs) will be written. The file is cleared on every instantiation — each
agent run starts with a fresh log. The parent directory is created automatically
by
ThreadLoggerManager if it does not exist.Instance Attributes
| Attribute | Type | Description |
|---|---|---|
self.model | str | The model identifier string passed to the constructor. |
self.logger_manager | ThreadLoggerManager | The logger manager instance. Keyed internally by (thread_id, log_file) so multiple agents running in threads write to separate files without locking. |
self.log | callable | Shortcut to self.logger_manager.log(message, level=logging.INFO). Call this inside forward to record any string to the chat history file. |
Abstract Method
forward. The signature is unconstrained at the base class level — concrete agents define their own parameter lists. Calling AgentSystem() directly or subclassing without implementing forward raises TypeError.
ThreadLoggerManager
ThreadLoggerManager (in utils/thread_logger.py) wraps Python’s standard logging module with thread-safety. It is used internally by AgentSystem but can also be used standalone.
utils/thread_logger.py
- Loggers are stored in a class-level dict keyed by
(thread_id, log_file). AThreadPoolExecutorrunning fiveTaskAgentinstances will therefore produce five independent log files with no interleaving. - The underlying
RotatingFileHandlercaps each file at 10 MB with up to 5 rotating backups. - Log entries are written with the format string
'%(message)s'— just the bare message, no timestamps or level prefixes — which keeps the chat history files human-readable as markdown.
Subclassing Pattern
The pattern used throughout HyperAgents is to override onlyforward and delegate all LLM calls to chat_with_agent, passing self.model and self.log:
AgentSystem.__init__ opens chat_history_file in write mode ('w') every
time a new instance is created, which truncates any existing content. If you
need to preserve logs across runs, copy the file before creating a new agent
instance.