Agents Module

The rakam_systems.generation.agents module provides classes for executing various actions such as query classification, prompt generation, and retrieval-augmented generation (RAG).

Classes

rakam_systems.generation.agents.Agent(model, ...)

rakam_systems.generation.agents.Action(...)

rakam_systems.generation.agents.ClassifyQuery(...)

rakam_systems.generation.agents.PromptGeneration(...)

rakam_systems.generation.agents.RAGGeneration(...)

Agent

class rakam_systems.generation.agents.Agent(model: str, api_key: str)

Bases: ABC

Represents the agent that can perform different actions based on input and state.

add_action(action_name: str, action: Action)

Adds an action to the agent’s set of available actions.

Parameters:
  • action_name – A string name for the action (e.g., ‘rag_generation’).

  • action – An instance of an Action subclass.

abstract choose_action(input: str, state: Any) Action

Abstract method to select an action based on input.

Parameters:

input – A string input based on which the action is selected.

Returns:

The selected Action instance.

execute_action(action_name: str, **kwargs)

Executes the selected action with the provided arguments.

Parameters:
  • action_name – The name of the action to execute.

  • kwargs – Arguments to pass to the action’s execute method.

Returns:

The result of the action’s execute method.

process_state(**kwargs) dict

Build a temporary state based on the input query.

Parameters:

input – The input query string.

Returns:

A dictionary representing the state.

Action

class rakam_systems.generation.agents.Action(agent, **kwargs)

Bases: ABC

Abstract base class for actions that agents can perform.

abstract execute(**kwargs)

ClassifyQuery

class rakam_systems.generation.agents.ClassifyQuery(agent, trigger_queries: Series, class_names: Series, embedding_model: str = 'all-MiniLM-L6-v2')

Bases: Action

Classifies a query by finding the closest match in a vector store using FAISS and SentenceTransformers.

build_vector_store(trigger_queries: Series, class_names: Series) VectorStores

Builds a VectorStores object from the trigger queries and class names.

execute(query: str)

Classifies the query by finding the closest match in the FAISS index.

PromptGeneration

class rakam_systems.generation.agents.PromptGeneration(agent, sys_prompt: str, prompt: str)

Bases: Action

Generates a prompt using a provided system prompt and user input. Supports streaming and non-streaming modes.

execute(query, prompt_kwargs: dict = {}, stream: bool = False)

RAGGeneration

class rakam_systems.generation.agents.RAGGeneration(agent, sys_prompt: str, prompt: str, vector_stores: VectorStores, vs_descriptions: dict | None = None)

Bases: Action

Performs Retrieval-Augmented Generation (RAG) by combining vector store search results with LLM generation.

execute(query, prompt_kwargs: dict = {}, stream: bool = False)