LLM Services
LLM Clients
- class econsimulacra.llm_services.clients.base.LLMClient(config, prng=None, registered_classes=[])[source]
Bases:
ABCLLM Client class (abstract class).
You can implement your own LLM client by inheriting this class and implementing the generate_response method. Currently, OpenAIClient and TransformersClient are implemented as built-in options.
See also
econsimulacra.llm_services.clients.OpenAIClient: LLM client implementation for OpenAI’s API.
econsimulacra.llm_services.clients.TransformersClient: LLM client implementation using the Transformers library and Outlines for structured generation.
- class econsimulacra.llm_services.clients.openai_client.OpenAIClient(config, prng=None, registered_classes=[])[source]
Bases:
LLMClientOpenAI client for interacting with OpenAI’s language models.
- Parameters:
prng (Optional[random.Random])
registered_classes (list[Type])
- class econsimulacra.llm_services.clients.transformers_client.TransformersClient(config, prng=None, registered_classes=[])[source]
Bases:
LLMClientTransformers client using Outlines for structured generation.
Prompt Builders
- class econsimulacra.llm_services.prompts.base.PromptBuilder(config, prng=None, registered_classes=[])[source]
Bases:
objectPrompt Builder class. Prompt builders are responsible for generating prompts except for the persona description (if applicable) i.e., they translate the observation into a prompt for LLM input. You can implement your own prompt builder by inheriting this class and implementing the build_prompt method.
Persona Builders
- class econsimulacra.llm_services.personas.base.PersonaBuilder(config, prng=None, registered_classes=[])[source]
Bases:
ABCPersona Builder class (abstract class).
You can implement your own persona builder by inheriting this class and implementing the build_persona method. Currently, Big5PersonaBuilder is implemented as a built-in option, which builds personas based on the Big5 personality traits.
See also: econsimulacra.llm_services.personas.big5.Big5PersonaBuilder
- abstractmethod build_persona(agent_id, agent_config)[source]
Register the agent to agent_id2persona_dic.
- Parameters:
- Return type:
None
Note
Called when LLMAgent is initialized. See also: econsimulacra.agents.llm_agent.LLMAgent._setup_env_services()
- build_persona_prompt(agent_id)[source]
Build persona prompt for the agent with the given agent_id.
- Parameters:
agent_id (int) – agent_id of the agent to build persona prompt for
- Returns:
persona prompt for the agent
- Return type:
Note
Called when LLMAgent.act is called. persona prompt contains the description and the persona information of the agent, and is used as part of the prompt for generation.
- class econsimulacra.llm_services.personas.scored_persona.ScoredPersonaBuilder(config, prng=None, registered_classes=[])[source]
Bases:
PersonaBuilderPersona builder that builds personas with scores.
The persona is represented as a dictionary of attributes and their corresponding scores.