sherpa_ai.config package#
Overview#
The config
package provides configuration management tools for Sherpa AI applications. It allows users to define and customize task-specific settings and parameters to control agent behavior.
Key Components
TaskConfig: Configuration class for defining task-specific settings
Configuration Management: Tools for loading and saving configurations
Parameter Validation: Ensures configuration parameters are valid
Example Usage#
from sherpa_ai.config import TaskConfig
# Create a task configuration
config = TaskConfig(
task_name="Question Answering",
model_name="gpt-4",
temperature=0.7,
max_tokens=1000
)
# Use the configuration with an agent
from sherpa_ai.agents import QAAgent
agent = QAAgent(config=config)
response = agent.get_response("What is artificial intelligence?")
Submodules#
Module |
Description |
---|---|
Provides the TaskConfig class for managing agent and task-specific configurations. |
sherpa_ai.config.task_config module#
- class sherpa_ai.config.task_config.AgentConfig(**data)[source]#
Bases:
BaseModel
Configuration settings for agent behavior and capabilities.
This class defines various configuration options that control how agents operate, including verbosity, search domains, reflection capabilities, and task agent usage.
- verbose#
Whether to enable verbose messaging during agent execution. Defaults to True.
- Type:
bool
- gsite#
List of domains to be used for Google search. Defaults to an empty list.
- Type:
list[str]
- do_reflect#
Whether to enable the reflection step for each agent. Defaults to False.
- Type:
bool
- use_task_agent#
Whether to enable use of task agent (obsolete). Defaults to False.
- Type:
bool
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig(verbose=True, gsite=["example.com"]) >>> print(config.verbose) True >>> print(config.search_domains) ['example.com']
-
verbose:
bool
#
-
gsite:
list
[str
]#
-
do_reflect:
bool
#
-
use_task_agent:
bool
#
- classmethod parse_gsite(value)[source]#
Parse a comma-separated string of URLs into a list.
- Parameters:
value (Optional[str]) – A comma-separated string of URLs.
- Returns:
A list of stripped URL strings.
- Return type:
list[str]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> result = AgentConfig.parse_gsite("example.com, test.com") >>> print(result) ['example.com', 'test.com']
- property search_domains: List[str]#
Get a list of valid search domains.
- Returns:
A list of valid URLs from the gsite attribute.
- Return type:
List[str]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig(gsite=["https://example.com", "invalid-url"]) >>> print(config.search_domains) ['https://example.com']
- property invalid_domains: List[str]#
Get a list of invalid search domains.
- Returns:
A list of invalid URLs from the gsite attribute.
- Return type:
List[str]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig(gsite=["https://example.com", "invalid-url"]) >>> print(config.invalid_domains) ['invalid-url']
- classmethod from_input(input_str)[source]#
Parse input string into AgentConfig.
This method extracts configuration parameters from a string that contains both content and configuration options. Configuration options are expected to be at the end of the string, separated by ‘–‘.
- Parameters:
input_str (str) – The input string containing content and configuration.
- Returns:
- A tuple containing the content part and the
parsed AgentConfig object.
- Return type:
Tuple[str, AgentConfig]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> content, config = AgentConfig.from_input("Hello world --gsite example.com") >>> print(content) Hello world >>> print(config.gsite) ['example.com']
- classmethod from_config(configs)[source]#
Create an AgentConfig from command-line style arguments.
This method parses a list of command-line style arguments and creates an AgentConfig object with the appropriate settings.
- Parameters:
configs (List[str]) – List of command-line style arguments.
- Returns:
A new AgentConfig instance with settings from the arguments.
- Return type:
- Raises:
ValueError – If invalid configuration options are provided.
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig.from_config(["--concise", "--gsite", "example.com"]) >>> print(config.verbose) False >>> print(config.gsite) ['example.com']
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- sherpa_ai.config.task_config.validate_url(url)[source]#
Check if a string is a valid URL.
This function validates a URL by checking if it has both a scheme and a netloc.
- Parameters:
url (str) – The URL string to validate.
- Returns:
True if the URL is valid, False otherwise.
- Return type:
bool
Example
>>> from sherpa_ai.config.task_config import validate_url >>> print(validate_url("https://example.com")) True >>> print(validate_url("invalid-url")) False
Module contents#
App configuration settings.
This module provides configuration settings for the Sherpa AI application, loading values from environment variables or a .env file. It includes settings for logging, language models, Slack integration, vector databases, and various API keys.
Usage:
First define variables in runtime environment or in your .env file. See .env-sample file for examples and a useful starting point. Then, in your code, use the values like this:
import Config as cfg secret = cfg.SLACK_SIGNING_SECRET another_variable = cfg.ANOTHER_ENVIRONMENT_VARIABLE
To add, remove, or change variables, … 1. Update this file to create the variables 2. Update env-sample to match 3. Update your own .env file and test the changes 4. Update corresponding secrets in Github and deployment environments
- class sherpa_ai.config.AgentConfig(**data)[source]#
Bases:
BaseModel
Configuration settings for agent behavior and capabilities.
This class defines various configuration options that control how agents operate, including verbosity, search domains, reflection capabilities, and task agent usage.
- verbose#
Whether to enable verbose messaging during agent execution. Defaults to True.
- Type:
bool
- gsite#
List of domains to be used for Google search. Defaults to an empty list.
- Type:
list[str]
- do_reflect#
Whether to enable the reflection step for each agent. Defaults to False.
- Type:
bool
- use_task_agent#
Whether to enable use of task agent (obsolete). Defaults to False.
- Type:
bool
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig(verbose=True, gsite=["example.com"]) >>> print(config.verbose) True >>> print(config.search_domains) ['example.com']
- classmethod from_config(configs)[source]#
Create an AgentConfig from command-line style arguments.
This method parses a list of command-line style arguments and creates an AgentConfig object with the appropriate settings.
- Parameters:
configs (List[str]) – List of command-line style arguments.
- Returns:
A new AgentConfig instance with settings from the arguments.
- Return type:
- Raises:
ValueError – If invalid configuration options are provided.
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig.from_config(["--concise", "--gsite", "example.com"]) >>> print(config.verbose) False >>> print(config.gsite) ['example.com']
- classmethod from_input(input_str)[source]#
Parse input string into AgentConfig.
This method extracts configuration parameters from a string that contains both content and configuration options. Configuration options are expected to be at the end of the string, separated by ‘–‘.
- Parameters:
input_str (str) – The input string containing content and configuration.
- Returns:
- A tuple containing the content part and the
parsed AgentConfig object.
- Return type:
Tuple[str, AgentConfig]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> content, config = AgentConfig.from_input("Hello world --gsite example.com") >>> print(content) Hello world >>> print(config.gsite) ['example.com']
- property invalid_domains: List[str]#
Get a list of invalid search domains.
- Returns:
A list of invalid URLs from the gsite attribute.
- Return type:
List[str]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig(gsite=["https://example.com", "invalid-url"]) >>> print(config.invalid_domains) ['invalid-url']
- model_config: ClassVar[ConfigDict] = {}#
Configuration for the model, should be a dictionary conforming to [ConfigDict][pydantic.config.ConfigDict].
- classmethod parse_gsite(value)[source]#
Parse a comma-separated string of URLs into a list.
- Parameters:
value (Optional[str]) – A comma-separated string of URLs.
- Returns:
A list of stripped URL strings.
- Return type:
list[str]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> result = AgentConfig.parse_gsite("example.com, test.com") >>> print(result) ['example.com', 'test.com']
- property search_domains: List[str]#
Get a list of valid search domains.
- Returns:
A list of valid URLs from the gsite attribute.
- Return type:
List[str]
Example
>>> from sherpa_ai.config.task_config import AgentConfig >>> config = AgentConfig(gsite=["https://example.com", "invalid-url"]) >>> print(config.search_domains) ['https://example.com']
-
verbose:
bool
#
-
gsite:
list
[str
]#
-
do_reflect:
bool
#
-
use_task_agent:
bool
#