superwise_api.entities.agent

class AgentApi(superwise_api.entities.base.BaseApi):

This class provides methods to interact with the Agent API.

Attributes:
  • api_client (ApiClient): An instance of the ApiClient to make requests.
  • _model_name (str): The name of the model.
  • _resource_path (str): The path of the resource.
AgentApi(api_client: superwise_api.client.api_client.ApiClient)

Initializes the DatasetApi class.

Arguments:
  • api_client (ApiClient): An instance of the SuperwiseApiClient to make requests.
def create( self, name: str, description: str = None, authentication_enabled: bool = False, observability_enabled: bool = True, **kwargs) -> superwise_api.models.agent.agent.Agent:

Creates a new agent.

Arguments:
  • name (str): The name of the agent.
  • description (str): The agent's description.
  • authentication_enabled (bool): Whether the agent requires an api token for access or not.
  • observability_enabled (bool): Whether the agent logs conversation to the db or not.
Returns:

Agent: The created agent.

def create_version( self, agent_id: str, name: str, agent_config: typing.Annotated[superwise_api.models.agent.agent.ReactAgentConfig | superwise_api.models.agent.agent.ContextChainConfig | superwise_api.models.agent.agent.BasicLLMConfig | superwise_api.models.agent.agent.FlowiseAppConfig, Discriminator(discriminator='type', custom_error_type=None, custom_error_message=None, custom_error_context=None)], description: str = None, **kwargs) -> superwise_api.models.agent.agent.Version:

Creates a new version for the agent.

Arguments:
  • agent_id (str): The id of the agent.
  • name (str): The name of the version.
  • description (str): The version's description.
  • agent_config (AgentConfig): agent configuration for this version.
Returns:

Version: The created version.

def update( self, agent_id: str, name: str | None = None, description: str | None = None, authentication_enabled: bool | None = None, observability_enabled: bool | None = None, **kwargs) -> superwise_api.models.agent.agent.Agent:

Updates the agent.

Arguments:
  • agent_id (str): The id of the agent.
  • name (str, optional): The new name of the agent.
  • description (str, optional): Description for the agent.
  • authentication_enabled (bool, optional): Whether the agent requires an api token for access or not.
  • observability_enabled (bool, optional): Whether the agent logs conversation to the db or not.
Returns:

Agent: The updated agent.

def update_version( self, version_id: str, agent_id: str, name: str | None = None, description: str | None = None, **kwargs) -> superwise_api.models.agent.agent.Version:

Updates the agent's version.

Arguments:
  • version_id (str): The version's id.
  • agent_id (str): The id of the version's agent.
  • name (str, optional): The new name of the version.
  • description (str, optional): New description for the version.
Returns:

Version: The updated version.

def get_version_by_id( self, agent_id: str, version_id: str, **kwargs) -> superwise_api.models.agent.agent.Version:

Retrieves an entity by its id.

Arguments:
  • agent_id (str): The id of the agent.
  • version_id (str): The id of the version to retrieve.
  • **kwargs: Arbitrary keyword arguments.
Returns:

Source: The retrieved entity.

def get_versions( self, agent_id: str, name: Optional[str] = None, created_by: Optional[str] = None, **kwargs) -> list[superwise_api.models.agent.agent.Version]:

Retrieves agent entities.

Arguments:
  • agent_id (str): The id of the agent.
  • **kwargs: Arbitrary keyword arguments.
Returns:

list[Version]: The retrieved entities.

def get( self, name: Optional[str] = None, created_by: Optional[str] = None, prompt: Optional[str] = None, dataset_id: Optional[str] = None, page: Optional[Annotated[int, Strict(strict=True), Interval(gt=None, ge=1, lt=None, le=None), None]] = None, size: Optional[Annotated[int, Strict(strict=True), Interval(gt=None, ge=1, lt=None, le=500), None]] = None, **kwargs) -> superwise_api.client.models.page.Page:

Gets agents. Filter if any of the parameters are provided.

Arguments:
  • name (str, optional): The name of the agent.
  • created_by (str, optional): The creator of the agent.
  • prompt (str, optional): The prompt of the agent.
  • dataset_id (str, optional): The id of the dataset.
  • page (int, optional): The page number.
  • size (int, optional): The size of the page.
Returns:

Page: A page of agents.

@BaseApi.raise_exception
def test_model_connection( self, llm_model: Annotated[Union[superwise_api.models.agent.agent.OpenAIModel, superwise_api.models.agent.agent.OpenAICompatibleModel, superwise_api.models.agent.agent.GoogleModel, superwise_api.models.agent.agent.AnthropicModel, superwise_api.models.agent.agent.VertexAIModelGardenModel], FieldInfo(annotation=NoneType, required=True, discriminator='provider')], **kwargs):

Tests the connection to the model. Raises exception on fail.

Arguments:
  • llm_model (ModelLLM): The model to test.
@BaseApi.raise_exception
def test_tool_connection(self, tool: superwise_api.models.tool.tool.ToolDef, **kwargs):

Tests the connection to the tool. Raises exception on fail.

Arguments:
  • tool (ToolDef): The tool to test.
@BaseApi.raise_exception
def ask_playground( self, input: str, agent_config: typing.Annotated[superwise_api.models.agent.agent.ReactAgentConfig | superwise_api.models.agent.agent.ContextChainConfig | superwise_api.models.agent.agent.BasicLLMConfig | superwise_api.models.agent.agent.FlowiseAppConfig, Discriminator(discriminator='type', custom_error_type=None, custom_error_message=None, custom_error_context=None)], chat_history: Optional[Sequence[dict]] = None, **kwargs) -> superwise_api.models.agent.playground.AskResponsePayload:

Performs ask request in playground mode.

Arguments:
  • input (str): The input to the model.
  • agent_config (AgentConfig): The type of the agent and connected tools/context.
  • chat_history (Sequence[dict], optional): The chat history.
Returns:

AskResponsePayload: The response payload.

@BaseApi.raise_exception
def ask_worker( self, agent_id: str, input: str, api_token: str | None = None, chat_history: Optional[Sequence[dict]] = None, **kwargs) -> superwise_api.models.agent.playground.AskResponsePayload:

Performs ask request to the specified worker.

Arguments:
  • agent_id (str): The agent asked.
  • input (str): The input to the model.
  • api_token (str): The API token of the agent.
  • chat_history (Sequence[dict], optional): The chat history.
Returns:

AskResponsePayload: The response payload.

def get_flowise_credential_schema( self, url: str, api_key: str, flow_id, **kwargs) -> superwise_api.models.agent.flowise.FlowiseCredentialUserInput:

Get credential schema.

Arguments:
  • url (str): url to the flowise agent.
  • api_key (str): Flow-relevant API key.
  • flow_id (str): ID of the requested flow.
  • **kwargs: Arbitrary keyword arguments.
Returns:

FlowiseCredentialUserInput: Required schema of the credentials.

@BaseApi.raise_exception
def regenerate_api_key(self, agent_id: str, **kwargs) -> superwise_api.models.agent.agent.Agent:

Regenerates api key for agent.

Arguments:
  • agent_id (str): The agent asked.
Returns:

Agent: Agent with the new api key.

def create_dataset( self, agent_id: str, name: str, **kwargs) -> superwise_api.models.dataset.dataset.Dataset:

Creates a new dataset for the agent.

Arguments:
  • agent_id (str): The id of the agent.
  • name (str): The name of the version.
Returns:

Dataset: The created dataset.

@BaseApi.raise_exception
def send_feedback( self, agent_id: str, payload: superwise_api.models.agent.feedback.EventFeedbackData, api_token: str | None = None, **kwargs) -> None:

Sends feedback to the specified worker for its answer.

Arguments:
  • agent_id (str): The agent receiving the feedback.
  • payload (EventFeedbackData): The feedback payload.
  • api_token (str): The API token of the application.
Returns:

None

Inherited Members
superwise_api.entities.base.BaseApi
api_client
wrap_api_calls
raise_exception
get_by_id
delete