LLM Services
LLM Clients
- class econsimulacra.llm_services.clients.base.LLMRecordConfig(save_path=None, save_num_tokens=False, save_prompt_response_pair=False)[source]
Bases:
objectConfiguration for recording LLM prompts and responses.
- 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.
- async generate_response_with_schema(prompt, json_schema)[source]
Generate a response using a request-specific action schema when supported.
- Parameters:
- Returns:
Parsed model response.
- Return type:
Note
The compatibility implementation delegates to
generate_response. Built-in structured clients override this method.
- get_action_schema(mobility_names)[source]
Build an action schema for one agent’s available mobility modes.
- Parameters:
mobility_names (list[str]) – Mobility names available to the agent.
- Returns:
Isolated, request-specific action schema.
- Return type:
Note
The stored or configured base schema is not mutated.
- 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])
- async generate_response(prompt)[source]
Generate a response from the OpenAI API based on the given prompt.
- Parameters:
prompt (str) – The input prompt to send to the OpenAI API.
- Returns:
The parsed JSON response from the OpenAI API.
- Return type:
Note
Existing callers use the client-level schema through the dynamic path.
- class econsimulacra.llm_services.clients.transformers_client.TransformersClient(config, prng=None, registered_classes=[])[source]
Bases:
LLMClientTransformers client using Outlines for structured generation.
- async generate_response(prompt)[source]
Generate a response from the model based on the given prompt.
- Parameters:
prompt (str) – The input prompt to send to the model.
- Returns:
The parsed JSON response from the model.
- Return type:
Note
Existing callers continue to use generators built from the base schema.
- class econsimulacra.llm_services.clients.text_base.TextGenerationClient[source]
Bases:
ABCAbstract service for asynchronous plain-text generation.
This interface is intentionally separate from
LLMClient, whose response contract is a structured action dictionary. Text-only consumers, such as the household tweet renderer, should not generate or parse the complete simulation action schema.
- class econsimulacra.llm_services.clients.transformers_text_client.TransformersTextClient(config, prng=None, registered_classes=[])[source]
Bases:
TextGenerationClientGenerate short plain text with a local Transformers causal LM.
- Parameters:
config (dict[str, Any]) – Service configuration. It must contain
modelNameand may containdevice,dtype,maxModelParameters,maxNewTokens,temperature,topP,repetitionPenalty,maxPromptTokens,maxConcurrentGenerations,numThreads,trustRemoteCode, andignoreGenerationErrors.prng (Optional[random.Random]) – Optional simulation pseudo-random generator.
registered_classes (list[Type]) – Registered classes accepted for compatibility with the environment service factory; unused by this implementation.
Unlike
TransformersClient, this service does not use an action JSON schema. It is intended for bounded surface realization after another component has already selected the semantic content.
- class econsimulacra.llm_services.clients.vllm_client.VLLMClient(config, prng=None, registered_classes=[])[source]
Bases:
LLMClient- async generate_response(prompt)[source]
Generate a response with the client’s configured action schema.
- Parameters:
prompt (str) – Input prompt sent to the vLLM server.
- Returns:
Parsed JSON response.
- Return type:
Note
This compatibility method delegates to the request-specific path.
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.