Skip to main content
A job instance can be created by adding a model to a survey with the by() method, or by using the Jobs class to create a job directly. For example:
It can be useful to work with jobs when you want to run a survey with multiple models, agents, or scenarios, or when you want to manage the execution of a survey in a more structured way. There are several methods available in the Jobs class to manage jobs, such as by(), run(), and list():
  • The by() method is used to add a model to the survey and create a job instance.
  • The run() method is used to execute the job.
  • The list() method is used to list details of jobs that have been posted to Expected Parrot.
  • The fetch() method is used to retrieve jobs that have been posted to Expected Parrot.
For example, to run the above job:
To retrieve details about your 10 most recent jobs posted to Expected Parrot:
The following information will be returned: You can also specify the page_size parameter to limit the number of jobs returned, and the page parameter to paginate through the jobs:
You can also filter jobs by their status using the status parameter:
You can filter jobs by description using the search_query parameter:
To fetch the Jobs objects directly you can use the fetch() method:
Or to fetch the associated results:

Prompts

It can also be useful to work with Jobs objects in order to inspect user and system prompts before running the job. For example, here we create a survey and use the job to inspect the prompts:
This will return the following information:

Jobs class

class edsl.jobs.Jobs(survey: Survey, agents: list[‘Agent’] | ‘AgentList’ | None = None, models: ‘ModelList’ | list[‘LanguageModel’] | None = None, scenarios: ‘ScenarioList’ | list[‘Scenario’] | None = None)[source]

Bases: Base A collection of agents, scenarios, models, and a survey that orchestrates interviews. The Jobs class is the central component for running large-scale experiments or simulations in EDSL. It manages the execution of interviews where agents interact with surveys through language models, possibly in different scenarios. Key responsibilities: 1. Managing collections of agents, scenarios, and models 2. Configuring execution parameters (caching, API keys, etc.) 3. Managing parallel execution of interviews 4. Handling remote cache and inference capabilities 5. Collecting and organizing results A typical workflow involves: 1. Creating a survey with questions 2. Creating a Jobs instance with that survey 3. Adding agents, scenarios, and models using the by() method 4. Running the job with run() or run_async() 5. Analyzing the results Jobs implements a fluent interface pattern, where methods return self to allow method chaining for concise, readable configuration.

init(survey: Survey, agents: list[‘Agent’] | ‘AgentList’ | None = None, models: ‘ModelList’ | list[‘LanguageModel’] | None = None, scenarios: ‘ScenarioList’ | list[‘Scenario’] | None = None)[source]

Initialize a Jobs instance with a survey and optional components. The Jobs constructor requires a survey and optionally accepts collections of agents, models, and scenarios. If any of these optional components are not provided, they can be added later using the by() method or will be automatically populated with defaults when the job is run.

Parameters

surveySurvey The survey containing questions to be used in the job agentsUnion[list[Agent], AgentList], optional The agents that will take the survey modelsUnion[ModelList, list[LanguageModel]], optional The language models to use scenariosUnion[ScenarioList, list[Scenario]], optional The scenarios to run

Raises

ValueError: If the survey contains questions with invalid names (e.g., names containing template variables)

Examples

Notes

  • The survey’s questions must have valid names without templating variables
  • If agents, models, or scenarios are not provided, defaults will be used when running
  • Upon initialization, a RunConfig is created with default environment and parameters

add_running_env(running_env: RunEnvironment) → Jobs[source]

Add a running environment to the job.

Args:

running_env: A RunEnvironment object containing details about the execution environment like API keys and other configuration.

Returns:

Jobs: The Jobs instance with the updated running environment.

Example:

property agents[source]

Get the agents associated with this job.

Returns

AgentList: The agents for this job.

all_question_parameters() → set[source]

Return all the fields in the questions in the survey.

by(**args: ‘Agent’ | ‘Scenario’ | ‘LanguageModel’ | Sequence[‘Agent’ | ‘Scenario’ | ‘LanguageModel’]*) → Jobs[source]

Add agents, scenarios, and language models to a job using a fluent interface. This method is the primary way to configure a Jobs instance with components. It intelligently handles different types of objects and collections, making it easy to build complex job configurations with a concise syntax.

Parameters

*argsUnion[Agent, Scenario, LanguageModel, Sequence[Union[Agent, Scenario, LanguageModel]]] Objects or sequences of objects to add to the job. Supported types are Agent, Scenario, LanguageModel, and sequences of these.

Returns

Jobs: The Jobs instance (self) for method chaining

Examples

Notes

  • All objects must implement ‘get_value’, ‘set_value’, and ‘add’ methods
  • Agent traits: When adding agents with traits to existing agents, the traits are combined. Avoid overlapping trait names to prevent unexpected behavior.
  • Scenario traits: When adding scenarios with traits to existing scenarios, new traits overwrite existing ones with the same name.
  • Models: New models with the same attributes will override existing models.
  • The method detects object types automatically and routes them to the appropriate collection (agents, scenarios, or models).

code()[source]

Return the code to create this instance.

static compute_job_cost(job_results: Results) → float[source]

Compute the cost of a completed job in USD.

create_bucket_collection() → BucketCollection[source]

Create a collection of buckets for each model. These buckets are used to track API calls and token usage. For test models and scripted response models, infinity buckets are used to avoid rate limiting delays.

duplicate()[source]

Create a duplicate copy of this Jobs instance.

Returns

Jobs: A new Jobs instance that is a copy of this one.

estimate_job_cost(iterations: int = 1) → dict[source]

Estimate the cost of running the job. Parameters: iterations – the number of iterations to run

estimate_job_cost_from_external_prices(price_lookup: dict, iterations: int = 1) → dict[source]

Estimate the cost of running the job using external price lookup.

Args:

price_lookup: Dictionary containing price information. iterations: Number of iterations to run.

Returns:

dict: Cost estimation details.

static estimate_prompt_cost(system_prompt: str, user_prompt: str, price_lookup: dict, inference_service: str, model: str) → dict[source]

Estimate the cost of running the prompts. Parameters:
  • iterations – the number of iterations to run
  • system_prompt – the system prompt
  • user_prompt – the user prompt
  • price_lookup – the price lookup
  • inference_service – the inference service
  • model – the model name

classmethod example(throw_exception_probability: float = 0.0, randomize: bool = False, test_model=False) → Jobs[source]

Return an example Jobs instance. Parameters:
  • throw_exception_probability – the probability that an exception will be thrown when answering a question. This is useful for testing error handling.
  • randomize – whether to randomize the job by adding a random string to the period
  • test_model – whether to use a test model
Jobs(…)

classmethod from_dict(data: dict) → Jobs[source]

Create a Jobs instance from a dictionary.

classmethod from_interviews(interview_list: list[‘Interview’]) → Jobs[source]

Return a Jobs instance from a list of interviews. This is useful when you have, say, a list of failed interviews and you want to create a new job with only those interviews.

generate_interviews() → Generator[source]

Generate interviews.
Note:Note that this sets the agents, model and scenarios if they have not been set. This is a side effect of the method. This is useful because a user can create a job without setting the agents, models, or scenarios, and the job will still run, with us filling in defaults.

html()[source]

Return the HTML representations for each scenario.

humanize(project_name: str = ‘Project’, scenario_list_method: Literal[‘randomize’, ‘loop’, ‘single_scenario’, ‘ordered’] | None = None, survey_description: str | None = None, survey_alias: str | None = None, survey_visibility: Literal[‘private’, ‘public’, ‘unlisted’] | None = ‘unlisted’, scenario_list_description: str | None = None, scenario_list_alias: str | None = None, scenario_list_visibility: Literal[‘private’, ‘public’, ‘unlisted’] | None = ‘unlisted’)[source]

Send the survey and scenario list to Expected Parrot. Then, create a project on Expected Parrot so you can share the survey with human respondents.

inspect()[source]

Create an interactive inspector widget for this job.

interviews() → list[source]

Return a list of edsl.jobs.interviews.Interview objects. It returns one Interview for each combination of Agent, Scenario, and LanguageModel. If any of Agents, Scenarios, or LanguageModels are missing, it fills in with defaults.

property models[source]

Get the models associated with this job.

Returns

ModelList: The models for this job.

property num_interviews*: int*[source]

Calculate the total number of interviews that will be run.
This is the product of the number of scenarios, agents, and models, multiplied by the number of iterations specified in the run configuration.

prompts(iterations=1) → Dataset[source]

Return a Dataset of prompts that will be used.

push(*args, **kwargs) → None[source]

Push the job to the remote server.

replace_missing_objects() → None[source]

If the agents, models, or scenarios are not set, replace them with defaults.

run(***, config: RunConfig) → ‘Results’ | None[source]

Run the job by conducting interviews and return their results. This is the main entry point for executing a job. It processes all interviews (combinations of agents, scenarios, and models) and returns a Results object containing all responses and metadata.

Parameters

configRunConfig Configuration object containing runtime parameters and environment settings nint, optional Number of iterations to run each interview (default: 1) progress_barbool, optional Whether to show a progress bar (default: False) stop_on_exceptionbool, optional Whether to stop the job if an exception is raised (default: False) check_api_keysbool, optional Whether to verify API keys before running (default: False) verbosebool, optional Whether to print extra messages during execution (default: True) print_exceptionsbool, optional Whether to print exceptions as they occur (default: True) remote_cache_descriptionstr, optional Description for entries in the remote cache remote_inference_descriptionstr, optional Description for the remote inference job remote_inference_results_visibilityVisibilityType, optional Visibility of results on Expected Parrot (“private”, “public”, “unlisted”) disable_remote_cachebool, optional Whether to disable the remote cache (default: False) disable_remote_inferencebool, optional Whether to disable remote inference (default: False) freshbool, optional Whether to ignore cache and force new results (default: False) skip_retrybool, optional Whether to skip retrying failed interviews (default: False) raise_validation_errorsbool, optional Whether to raise validation errors (default: False) backgroundbool, optional Whether to run in background mode (default: False) job_uuidstr, optional UUID for the job, used for tracking cacheCache, optional Cache object to store results bucket_collectionBucketCollection, optional Object to track API keys key_lookupKeyLookup, optional Object to manage API keys memory_thresholdint, optional Memory threshold in bytes for the Results object’s SQLList, controlling when data is offloaded to SQLite storage new_formatbool, optional If True, uses remote_inference_create method, if False uses old_remote_inference_create method (default: True) expected_parrot_api_keystr, optional Custom EXPECTED_PARROT_API_KEY to use for this job run

Returns

Results: A Results object containing all responses and metadata

Notes

  • This method will first try to use remote inference if available
  • If remote inference is not available, it will run locally
  • For long-running jobs, consider using progress_bar=True
  • For maximum performance, ensure appropriate caching is configured
Example:

run_async(***, config: RunConfig) → Results[source]

Asynchronously runs the job by conducting interviews and returns their results. This method is the asynchronous version of run(). It has the same functionality and parameters but can be awaited in an async context for better integration with asynchronous code.

Parameters

configRunConfig Configuration object containing runtime parameters and environment settings nint, optional Number of iterations to run each interview (default: 1) progress_barbool, optional Whether to show a progress bar (default: False) stop_on_exceptionbool, optional Whether to stop the job if an exception is raised (default: False) check_api_keysbool, optional Whether to verify API keys before running (default: False) verbosebool, optional Whether to print extra messages during execution (default: True) print_exceptionsbool, optional Whether to print exceptions as they occur (default: True) remote_cache_descriptionstr, optional Description for entries in the remote cache remote_inference_descriptionstr, optional Description for the remote inference job remote_inference_results_visibilityVisibilityType, optional Visibility of results on Expected Parrot (“private”, “public”, “unlisted”) disable_remote_cachebool, optional Whether to disable the remote cache (default: False) disable_remote_inferencebool, optional Whether to disable remote inference (default: False) freshbool, optional Whether to ignore cache and force new results (default: False) skip_retrybool, optional Whether to skip retrying failed interviews (default: False) raise_validation_errorsbool, optional Whether to raise validation errors (default: False) backgroundbool, optional Whether to run in background mode (default: False) job_uuidstr, optional UUID for the job, used for tracking cacheCache, optional Cache object to store results bucket_collectionBucketCollection, optional Object to track API calls key_lookupKeyLookup, optional Object to manage API keys memory_thresholdint, optional Memory threshold in bytes for the Results object’s SQLList, controlling when data is offloaded to SQLite storage new_formatbool, optional If True, uses remote_inference_create method, if False uses old_remote_inference_create method (default: True) expected_parrot_api_keystr, optional Custom EXPECTED_PARROT_API_KEY to use for this job run

Returns

Results: A Results object containing all responses and metadata

Notes

  • This method should be used in async contexts (e.g., with await)
  • For non-async contexts, use the run() method instead
  • This method is particularly useful in notebook environments or async applications
Example:

property scenarios*: ScenarioList*[source]

Get the scenarios associated with this job.

Returns

ScenarioList: The scenarios for this job.

show_flow(filename: str | None = None) → None[source]

Visualize either the Job dependency/post-processing flow or the underlying survey flow. The method automatically decides which flow to render:
  1. If the job has dependencies created via Jobs.to() (i.e. _depends_on is not None) or has post-run methods queued in _post_run_methods, the job flow (dependencies → post-processing chain) is rendered using edsl.jobs.job_flow_visualization.JobsFlowVisualization.
  2. Otherwise, it falls back to the original behaviour and shows the survey question flow using edsl.surveys.survey_flow_visualization.SurveyFlowVisualization.

show_prompts(all: bool = False) → None[source]

Print the prompts.

table()[source]

Return a table view of the job’s prompts.

Returns

Table representation of the job’s prompts.

then(method_name, *args, **kwargs) → Jobs[source]

Schedule a method to be called on the results object after the job runs. This allows for method chaining like: jobs.then(‘to_scenario_list’).then(‘to_pandas’).then(‘head’, 10)

Args:

method_name: Name of the method to call on the results *args: Positional arguments to pass to the method **kwargs: Keyword arguments to pass to the method

to(question_or_survey_or_jobs: ‘Question’ | ‘Survey’ | ‘Jobs’) → Jobs[source]

Create a new Jobs instance from self and a target object. The target can be one of the following:
  • Question – A single question which will be wrapped in a one-question survey.
  • Survey – A survey object that will be used directly.
  • Jobs – An existing Jobs object. In this case the target Jobs is returned unchanged, but its _depends_on attribute is set to reference self, establishing an execution dependency chain.

Args:

question_or_survey_or_jobs (Union[Question, Survey, Jobs]): The object used to build (or identify) the new Jobs instance.

Returns:

Jobs: A new Jobs instance that depends on the current instance, or the target Jobs instance when the target itself is a Jobs.

Raises:

ValueError: If question_or_survey_or_jobs is not one of the supported types.

Examples:

The following doctest demonstrates sending one job to another and verifying the dependency link via the private _depends_on attribute:

to_dict(add_edsl_version=True, full_dict=None)[source]

Convert the Jobs instance to a dictionary representation.

Args:

add_edsl_version: Whether to include EDSL version information. full_dict: Additional dictionary to merge (currently unused).

Returns:

dict: Dictionary representation of this Jobs instance.

use_remote_cache() → bool[source]

Determine whether to use remote cache for this job.

Returns

bool: True if remote cache should be used, False otherwise.

using(obj) → Jobs[source]

Add a Cache, BucketCollection, or KeyLookup object to the job.

Args:

obj: The object to add to the job’s configuration. Must be one of: Cache, BucketCollection, or KeyLookup.

Returns:

Jobs: The Jobs instance with the updated configuration object.

using_bucket_collection(bucket_collection: BucketCollection) → Jobs[source]

Add a BucketCollection object to the job.

Args:

bucket_collection: The BucketCollection object to add to the job’s configuration.

Returns:

Jobs: The Jobs instance with the updated bucket collection.

using_cache(cache: Cache) → Jobs[source]

Add a Cache object to the job.

Args:

cache: The Cache object to add to the job’s configuration.

Returns:

Jobs: The Jobs instance with the updated cache.

using_key_lookup(key_lookup: KeyLookup) → Jobs[source]

Add a KeyLookup object to the job.

Args:

key_lookup: The KeyLookup object to add to the job’s configuration.

Returns:

Jobs: The Jobs instance with the updated key lookup.

where(expression: str) → Jobs[source]

Filter the agents, scenarios, and models based on a condition. Parameters: expression – a condition to filter the agents, scenarios, and models