iclbench.agents packageο
Submodulesο
iclbench.agents.base moduleο
- class iclbench.agents.base.BaseAgent(client_factory, prompt_builder)[source]ο
Bases:
objectBase class for all agents in the ICLBench framework.
The BaseAgent class serves as a foundational class for creating agents that interact with environments using a client for language model interactions and a prompt builder to manage context. It provides methods for performing actions based on observations, updating the prompt with observations and actions, and resetting the prompt builder.
- Variables:
client (Client) β An instance of the client created by the client factory.
prompt_builder (PromptBuilder) β An instance of the prompt builder for managing prompt context and history.
- __init__(client_factory, prompt_builder)[source]ο
Initializes the BaseAgent with a client factory and a prompt builder.
- Parameters:
client_factory (Callable) β A factory function to create a client instance.
prompt_builder (PromptBuilder) β An instance of the prompt builder.
- act(obs)[source]ο
Abstract method for performing an action based on the given observation.
This method must be implemented by subclasses, as the action logic will depend on the specific agent type. For instance, derived agents may store action-observation histories when acting.
- Parameters:
obs (Observation) β The current observation from the environment.
- reset()[source]ο
Resets the prompt builder to its initial state.
This method clears the prompt history and any other stored information in the prompt builder, allowing for a fresh start in a new episode or task.
- update_prompt(observation, action)[source]ο
Updates the prompt builder with the latest observation and action.
This method incorporates the current observation and the action taken into the prompt history, allowing for context to be maintained across interactions.
- Parameters:
observation (Observation) β The current observation from the environment.
action (Action) β The action taken by the agent.
iclbench.agents.chain_of_thought moduleο
- class iclbench.agents.chain_of_thought.ChainOfThoughtAgent(client_factory: LLMClientWrapper, prompt_builder, config)[source]ο
Bases:
BaseAgent- __init__(client_factory: LLMClientWrapper, prompt_builder, config)[source]ο
Initializes the BaseAgent with a client factory and a prompt builder.
- Parameters:
client_factory (Callable) β A factory function to create a client instance.
prompt_builder (PromptBuilder) β An instance of the prompt builder.
- act(obs, prev_action=None)[source]ο
Abstract method for performing an action based on the given observation.
This method must be implemented by subclasses, as the action logic will depend on the specific agent type. For instance, derived agents may store action-observation histories when acting.
- Parameters:
obs (Observation) β The current observation from the environment.
iclbench.agents.dummy moduleο
- class iclbench.agents.dummy.DummyAgent(client_factory, prompt_builder)[source]ο
Bases:
BaseAgentFor debugging.
- __init__(client_factory, prompt_builder)[source]ο
Initializes the BaseAgent with a client factory and a prompt builder.
- Parameters:
client_factory (Callable) β A factory function to create a client instance.
prompt_builder (PromptBuilder) β An instance of the prompt builder.
- act(obs, prev_action=None)[source]ο
Abstract method for performing an action based on the given observation.
This method must be implemented by subclasses, as the action logic will depend on the specific agent type. For instance, derived agents may store action-observation histories when acting.
- Parameters:
obs (Observation) β The current observation from the environment.
- class iclbench.agents.dummy.LLMResponse(model_id, completion, stop_reason, input_tokens, output_tokens, reasoning)ο
Bases:
tuple- completionο
Alias for field number 1
- input_tokensο
Alias for field number 3
- model_idο
Alias for field number 0
- output_tokensο
Alias for field number 4
- reasoningο
Alias for field number 5
- stop_reasonο
Alias for field number 2
iclbench.agents.icl moduleο
- class iclbench.agents.icl.ICLAgent(client_factory, prompt_builder)[source]ο
Bases:
BaseAgent- __init__(client_factory, prompt_builder)[source]ο
Initializes the BaseAgent with a client factory and a prompt builder.
- Parameters:
client_factory (Callable) β A factory function to create a client instance.
prompt_builder (PromptBuilder) β An instance of the prompt builder.
- act(obs, prev_action=None)[source]ο
Abstract method for performing an action based on the given observation.
This method must be implemented by subclasses, as the action logic will depend on the specific agent type. For instance, derived agents may store action-observation histories when acting.
- Parameters:
obs (Observation) β The current observation from the environment.
iclbench.agents.naive moduleο
- class iclbench.agents.naive.NaiveAgent(client_factory, prompt_builder)[source]ο
Bases:
BaseAgent- __init__(client_factory, prompt_builder)[source]ο
Initializes the BaseAgent with a client factory and a prompt builder.
- Parameters:
client_factory (Callable) β A factory function to create a client instance.
prompt_builder (PromptBuilder) β An instance of the prompt builder.
- act(obs, prev_action=None)[source]ο
Abstract method for performing an action based on the given observation.
This method must be implemented by subclasses, as the action logic will depend on the specific agent type. For instance, derived agents may store action-observation histories when acting.
- Parameters:
obs (Observation) β The current observation from the environment.
iclbench.agents.self_refine moduleο
- class iclbench.agents.self_refine.SelfRefineAgent(client_factory: LLMClientWrapper, prompt_builder, max_iterations=3)[source]ο
Bases:
BaseAgent- __init__(client_factory: LLMClientWrapper, prompt_builder, max_iterations=3)[source]ο
Initializes the BaseAgent with a client factory and a prompt builder.
- Parameters:
client_factory (Callable) β A factory function to create a client instance.
prompt_builder (PromptBuilder) β An instance of the prompt builder.
- act(obs, prev_action=None)[source]ο
Abstract method for performing an action based on the given observation.
This method must be implemented by subclasses, as the action logic will depend on the specific agent type. For instance, derived agents may store action-observation histories when acting.
- Parameters:
obs (Observation) β The current observation from the environment.
Module contentsο
- class iclbench.agents.AgentFactory(config)[source]ο
Bases:
objectA factory class for creating various types of agents based on the provided configuration.
The AgentFactory class encapsulates the logic for creating agents used in the ICLBench framework. It generates agents of different types, each tailored for specific tasks and functionality.
- Variables:
config (Config) β The configuration object containing settings for agent creation, including agent type and client configuration.
- Parameters:
config (Config) β
The configuration settings for the agent, which must include: - agent.type (str): The type of agent to create. Supported types include:
βnaiveβ
βiclβ
βcotβ
βself_refineβ
βdummyβ
client (dict): The client configuration for the agent.
- create_agent()[source]ο
Creates an instance of the agent based on the configuration settings.
- Returns:
- An instance of the specified agent type, which could be:
NaiveAgent
ICLAgent
ChainOfThoughtAgent
SelfRefineAgent
DummyAgent
- Return type:
Agent
- Raises:
ValueError β If the specified agent type in the configuration is not recognized.