Skip to main content

Conversational graph package

Project description

Conversational Graph

A Python package for building stateful, graph-based conversational agents. Control the flow of your AI conversations with precision using states, transitions, and tools.

Installation

pip install videosdk-conversational-graph

Features

  • Graph-Based Flow Control: Define conversations as a graph of states and transitions.
  • State Management: Manage conversation context and strict progression between logical steps.
  • Tool Integration: Integrate HTTP request tools to specific states.
  • Data Modeling: Strongly typed data extraction using Pydantic models.

Quick Start

Here is a simple example of how to build a strict conversational flow for a loan assistant.

from conversational_graph import ConversationalGraph, ConversationalDataModel, PreDefinedTool, HttpToolRequest

get_weather = PreDefinedTool().http_tool(HttpToolRequest(
        name="get_weather",
        description="Called when the user asks about the weather. This function will return the weather for the given location.",
        url="https://api.open-meteo.com/v1/forecast?latitude=21.1702&longitude=81.2402&current=temperature_2m",
        method="GET"
    )
)

# Provide Data Model with validation rules in descriptions for each field.
class LoanFlow(ConversationalDataModel):
    loan_type: str = Field(None, description="Type of loan: personal, home")
    annual_income: int = Field(None, description="Annual income of the applicant in INR")
    credit_score: int = Field(None, description="Credit score of the applicant. Must be between 300 and 850")
    property_value: int = Field(None, description="Value of the property for home loan in INR")
    loan_amount: int = Field(None, description="Desired loan amount in INR. MUST be greater than ₹11 lakh for approval")

loan_application = ConversationalGraph(
        name="Loan Application",
        DataModel= LoanFlow,
        off_topic_threshold=5,
        graph_type="STRICT"
    )
    
# Start Greeting
q0 = loan_application.state(
    name="Greeting",
    instruction="Welcome user and start the conversation and tell the weather",
    tool=get_weather
)

# Loan Type Selection
q1 = loan_application.state(
    name="Loan Type Selection",
    instruction="Ask user to select loan type. We only offer personal loan and home loan at the moment.",
)

# Personal Loan Details
q1a = loan_application.state(
    name="Personal Loan Details",
    instruction="Collect annual income and credit score for personal loan. Annual income must be > ₹5 lakh and credit score > 500."
)

# Home Loan Details
q1b = loan_application.state(
    name="Home Loan Details",
    instruction="Collect annual income, credit score, and property value for home loan. Annual income must be > ₹6 lakh, credit score > 650, and property value must be reasonable."
)

# Merged State → Loan Amount Collection
q2 = loan_application.state(
    name="Loan Amount Collection",
    instruction="Collect the desired loan amount. Minimum loan amount is ₹11 lakh for approval."
)


q2a = loan_application.state(
    name="Loan Amount Rejection",
    instruction="Inform user that the requested loan amount is below the minimum requirement of ₹11 lakh and politely end the application process."
)   

q2b = loan_application.state(
    name="Loan Amount Acceptance",
    instruction="Proceed to the next step of the application process as the requested loan amount meets the minimum requirement."
)

q3 = loan_application.state(
    name="Loan Application Complete",
    instruction="Inform user that the application has been submitted successfully"
)

# Master / Off-topic handler
q_master = loan_application.state(
    name="Off-topic Handler",
    instruction="Handle off-topic or inappropriate inputs respectfully and end the call politely",
    master=True
)


# Define Transitions

# Greeting → Loan Type Selection
loan_application.transition(
    from_state=q0,
    to_state=q1,
    condition="User ready to apply for loan"
)

# Branch from Loan Type Selection
loan_application.transition(
    from_state=q1,
    to_state=q1a,
    condition="User wants personal loan"
)

loan_application.transition(
    from_state=q1,
    to_state=q1b,
    condition="User wants home loan"
)

# Merge all branches → Loan Amount Collection
loan_application.transition(
    from_state=q1a,
    to_state=q2,
    condition="Personal loan details collected and verified"
)

loan_application.transition(
    from_state=q1b,
    to_state=q2,
    condition="Home loan details collected and verified"
)

# Loan Amount → Review and Confirm
loan_application.transition(
    from_state=q2,
    to_state=q2a,
    condition="Loan application rejected due to insufficient amount (< ₹11 lakh)"
)

loan_application.transition(
    from_state=q2,
    to_state=q2b,
    condition="Loan amount meets minimum requirement (≥ ₹11 lakh)"
)

# Review → Complete
loan_application.transition(
    from_state=q2b,
    to_state=q3,
    condition="User confirms submission of loan application"
)

Core Concepts

ConversationalGraph

The main entry point. It holds all your states and transitions.

  • name: Name of your conversational graph.
  • DataModel: A Pydantic model class that defines the schema for data you want to collect during the conversation.
  • off_topic_threshold: Number of times the conversation can go off-topic before the flow jumps to the master state.
  • graph_type: Currently supports "STRICT" for rigid flows.

State

A node in the conversation graph.

  • name: Name of the state.
  • instruction: Instructions for the LLM on what to do in this state.
  • tool: A Python function to execute in this state (optional).
  • master: If True, this state acts as a master state (optional).
  • required_fields: List of field names (matching your DataModel) that must be collected or present before the tool can run or the state is considered 'complete' (optional).

Transition

Defines the valid paths between states.

  • from_state: Source state name.
  • to_state: Destination state name.
  • condition: Description of when this transition should happen. The LLM uses this to decide the next step.

Edge Cases

  • There can be zero or one master state.
  • Tools must be accessible.
  • Every transition must point to an existing state.
  • There can only be one start state.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

videosdk_conversational_graph-0.0.5.tar.gz (5.0 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

videosdk_conversational_graph-0.0.5-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

videosdk_conversational_graph-0.0.5-cp313-cp313-win_amd64.whl (266.2 kB view details)

Uploaded CPython 3.13Windows x86-64

videosdk_conversational_graph-0.0.5-cp313-cp313-win32.whl (232.7 kB view details)

Uploaded CPython 3.13Windows x86

videosdk_conversational_graph-0.0.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

videosdk_conversational_graph-0.0.5-cp313-cp313-macosx_11_0_arm64.whl (302.2 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

videosdk_conversational_graph-0.0.5-cp312-cp312-win_amd64.whl (267.3 kB view details)

Uploaded CPython 3.12Windows x86-64

videosdk_conversational_graph-0.0.5-cp312-cp312-win32.whl (233.7 kB view details)

Uploaded CPython 3.12Windows x86

videosdk_conversational_graph-0.0.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64manylinux: glibc 2.28+ x86-64

videosdk_conversational_graph-0.0.5-cp312-cp312-macosx_11_0_arm64.whl (304.0 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

Details for the file videosdk_conversational_graph-0.0.5.tar.gz.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5.tar.gz
Algorithm Hash digest
SHA256 992b0595e9cd6946cbbee843665ff3dc448cd686141eb1e1d84d969fa272dc7d
MD5 a0a5dda70611433a076e30871b2fa0c9
BLAKE2b-256 1c863470b854d743d21bde9b0e2b80c854a462074a53c280c7c42dbe7a5c266a

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b72dad6102a04e986cd39963048cf9b43b884b85b91d5dec3342356b45eef9c5
MD5 48ee50799f2e2b04ba0c864b5912fbbc
BLAKE2b-256 9c1762a40336178d0725a0570ad5a7472f777ed830b372cfe3453313ab827ec8

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp313-cp313-win_amd64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 ec3db08f768bbaaed0f889c71ed230f738b048eee77afb61f4f42a685686cb73
MD5 bf7f2e3072864aa2f7b6380fe99455a6
BLAKE2b-256 9ea282dcf0569f5c15507e0bc3ea3dd3e3ccfbd1cbb580427b22e4f8f466a829

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp313-cp313-win32.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 90a0e2f24fe50de7a1659dfbe8f1d71beaa25af49bf92f489476ba408c1296ad
MD5 4b2cef4577d081e17711119cd946beb0
BLAKE2b-256 e1a7d530b02e518421bd9292a2d18c646b82e0a1689bd2a1bd34dfa73d8e3528

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 0adfb1be6bf1c5f7116734c88ebae268942053ef9e407777f3688c0f794aee73
MD5 d3b63b2e5ba89c6a56130ba59b079e53
BLAKE2b-256 e5525f535949606325a8a5a807b407431a41478f45dc473b23a1bb0c2eb05824

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 dac62f090bc769cc9f831b00104578b5fd37417b41c78c8cc5bcb0d65bf89d3a
MD5 b1f58fa3f20a1e439a6a7dbb81771d8b
BLAKE2b-256 46340c0e3081d12efc2b2e2bf22b372deda2ab2a92f77a40603b5009b0ad7803

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 71c4f6b68a01519ad5b4270775bec2e09883a7202b64067aebcf7440faa6f3db
MD5 e7b644486c26c1e1913613f888c83106
BLAKE2b-256 61477db342f87d9680504d7ffff3cdefea3c2adcf1d7698014879794b2c6bac5

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp312-cp312-win32.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 5f90c03660f528194eaf958817f2e637814453db4d767a88942cff0100453a80
MD5 0761800fdc4e45f40c2bf82170f81134
BLAKE2b-256 416582ec99600f18e88c0f0ecc023dc054dbd97a4dd6cd43e3d9f11b51d24f5a

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 645cb56753c09b8ad352d0124efe8996198262180509b3380035441dc51b7158
MD5 dede5f0fc06e9689c0bb5dbcb65ab100
BLAKE2b-256 096be40ca44d763ea67138c34095d93a919129932c459b5e50f386588d5daec6

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.5-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 821d94c1c850d2d91564a410ecd2c3c44d57fb9809dee0817660f93c4b7fac67
MD5 473b4e7c86dc44a627fa5a52491ed018
BLAKE2b-256 071f4759973c1129db140c8a14ae384ad2b6a8aee5e448c4a4b029c8ec7b0768

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page