Generative Agent-Based Model

raw JSON →
0.2.18 verified Sat May 09 auth: no python

Generative Agent-Based Model (GABM) framework for building agent-based models using LLMs. Current version 0.2.18, requires Python >=3.12. Active development on GitHub.

pip install gabm
error ModuleNotFoundError: No module named 'gabm'
cause Library not installed or installed in wrong environment.
fix
Run pip install gabm. Verify Python version >=3.12.
error TypeError: Model.__init__() missing 1 required positional argument: 'llm_api_key'
cause Model expects `llm_api_key` parameter but it was omitted.
fix
Provide llm_api_key when creating Model: Model(agents=[], llm_api_key='your-key').
deprecated In version 0.2.15, `gabm.LLMAgent` was renamed to `gabm.Agent`. Old import will be removed in 0.3.0.
fix Use `from gabm import Agent` instead of `from gabm import LLMAgent`.
gotcha The `Model` constructor requires `llm_api_key` explicitly; it does not read environment variables automatically.
fix Always pass `llm_api_key=os.environ.get('OPENAI_API_KEY', '')` or set via argument.
gotcha Agent `act` method must return a string. Returning non-string leads to silent failure.
fix Ensure `act` returns a string, e.g., `return str(...)`.

Basic usage: define custom agent, create model with agents, run simulation.

import os
from gabm import Model, Agent

class MyAgent(Agent):
    def act(self, context):
        return f"Agent {self.id} acting on {context}"

model = Model(
    agents=[MyAgent(id=1), MyAgent(id=2)],
    llm_api_key=os.environ.get('OPENAI_API_KEY', '')
)
model.run(steps=3)