gpt_engineer.applications.cli.cli_agent.CliAgent
- class gpt_engineer.applications.cli.cli_agent.CliAgent(memory: ~typing.MutableMapping[str | ~pathlib.Path, str], execution_env: ~gpt_engineer.core.base_execution_env.BaseExecutionEnv, ai: ~gpt_engineer.core.ai.AI = None, code_gen_fn: ~gpt_engineer.applications.cli.cli_agent.CodeGenType = <function gen_code>, improve_fn: ~gpt_engineer.applications.cli.cli_agent.ImproveType = <function improve_fn>, process_code_fn: ~gpt_engineer.applications.cli.cli_agent.CodeProcessor = <function execute_entrypoint>, preprompts_holder: ~gpt_engineer.core.preprompts_holder.PrepromptsHolder = None)[source]
Bases:
BaseAgentThe CliAgent class is responsible for managing the lifecycle of code generation and improvement using an AI model. It orchestrates the generation of new code and the improvement of existing code based on given prompts and utilizes a memory system and execution environment for processing.
- Parameters:
memory (BaseMemory) – An instance of a class that adheres to the BaseMemory interface, used for storing and retrieving information during the code generation process.
execution_env (BaseExecutionEnv) – An instance of a class that adheres to the BaseExecutionEnv interface, used for executing code and managing the execution environment.
ai (AI, optional) – An instance of the AI class that manages calls to the language model. If not provided, a default instance is created.
code_gen_fn (CodeGenType, optional) – A callable that takes an AI instance, a prompt, and a memory instance to generate code. Defaults to the gen_code function.
improve_fn (ImproveType, optional) – A callable that takes an AI instance, a prompt, a FilesDict instance, and a memory instance to improve code. Defaults to the improve function.
process_code_fn (CodeProcessor, optional) – A callable that takes an AI instance, an execution environment, and a FilesDict instance to process code. Defaults to the execute_entrypoint function.
preprompts_holder (PrepromptsHolder, optional) – An instance of PrepromptsHolder that manages preprompt templates. If not provided, a default instance is created using the PREPROMPTS_PATH.
- memory
The memory instance where the agent stores and retrieves information.
- Type:
BaseMemory
- execution_env
The execution environment instance where the agent executes and manages code.
- Type:
- ai
The AI instance used for interacting with the language model.
- Type:
AI
- code_gen_fn
The function used for generating code.
- Type:
CodeGenType
- improve_fn
The function used for improving code.
- Type:
ImproveType
- process_code_fn
The function used for processing code.
- Type:
CodeProcessor
- preprompts_holder
The holder for preprompt templates.
- Type:
PrepromptsHolder
- improve(files_dict: FilesDict, prompt: Prompt, execution_command: str | None = None, diff_timeout=3) FilesDict[source]
Improves an existing piece of code using the AI and step bundle based on the provided prompt.
- Parameters:
files_dict (FilesDict) – An instance of FilesDict containing the code to be improved.
prompt (str) – A string prompt that guides the code improvement process.
execution_command (str, optional) – An optional command to execute the code. If not provided, the default execution command is used.
- Returns:
An instance of the FilesDict class containing the improved code.
- Return type:
- init(prompt: Prompt) FilesDict[source]
Generates a new piece of code using the AI and step bundle based on the provided prompt.
- Parameters:
prompt (str) – A string prompt that guides the code generation process.
- Returns:
An instance of the FilesDict class containing the generated code.
- Return type:
- classmethod with_default_config(memory: ~gpt_engineer.core.default.disk_memory.DiskMemory, execution_env: ~gpt_engineer.core.default.disk_execution_env.DiskExecutionEnv, ai: ~gpt_engineer.core.ai.AI = None, code_gen_fn: ~gpt_engineer.applications.cli.cli_agent.CodeGenType = <function gen_code>, improve_fn: ~gpt_engineer.applications.cli.cli_agent.ImproveType = <function improve_fn>, process_code_fn: ~gpt_engineer.applications.cli.cli_agent.CodeProcessor = <function execute_entrypoint>, preprompts_holder: ~gpt_engineer.core.preprompts_holder.PrepromptsHolder = None, diff_timeout=3)[source]
Creates a new instance of CliAgent with default configurations for memory, execution environment, AI, and other functional parameters.
- Parameters:
memory (DiskMemory) – An instance of DiskMemory for storing and retrieving information.
execution_env (DiskExecutionEnv) – An instance of DiskExecutionEnv for executing code.
ai (AI, optional) – An instance of AI for interacting with the language model. Defaults to None, which will create a new AI instance.
code_gen_fn (CodeGenType, optional) – A function for generating code. Defaults to gen_code.
improve_fn (ImproveType, optional) – A function for improving code. Defaults to improve.
process_code_fn (CodeProcessor, optional) – A function for processing code. Defaults to execute_entrypoint.
preprompts_holder (PrepromptsHolder, optional) – An instance of PrepromptsHolder for managing preprompt templates. Defaults to None, which will create a new PrepromptsHolder instance using PREPROMPTS_PATH.
- Returns:
An instance of CliAgent configured with the provided or default parameters.
- Return type: