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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

videosdk_conversational_graph-0.0.6-cp313-cp313-win_amd64.whl (268.6 kB view details)

Uploaded CPython 3.13Windows x86-64

videosdk_conversational_graph-0.0.6-cp313-cp313-win32.whl (234.9 kB view details)

Uploaded CPython 3.13Windows x86

videosdk_conversational_graph-0.0.6-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.6-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (1.9 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

videosdk_conversational_graph-0.0.6-cp313-cp313-macosx_11_0_arm64.whl (304.6 kB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

videosdk_conversational_graph-0.0.6-cp312-cp312-win_amd64.whl (269.7 kB view details)

Uploaded CPython 3.12Windows x86-64

videosdk_conversational_graph-0.0.6-cp312-cp312-win32.whl (236.3 kB view details)

Uploaded CPython 3.12Windows x86

videosdk_conversational_graph-0.0.6-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.6-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl (2.0 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.28+ ARM64

videosdk_conversational_graph-0.0.6-cp312-cp312-macosx_11_0_arm64.whl (306.4 kB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

File details

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

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp313-cp313-win_amd64.whl
Algorithm Hash digest
SHA256 af600e995ecaa2527f9e73d9a256505667ed8b1d2607a6602af305f7dea6ed52
MD5 86cfd831db870b88bca9e93bc5de42ea
BLAKE2b-256 3381bc7bb79ab7de5337e0acc68de2ca649721791e949d77eddf2e154bc3cdff

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp313-cp313-win32.whl
Algorithm Hash digest
SHA256 d504a3574e60dfd2fef690801049d385a6ceda7afa457bfee2bf60cd5f2164b2
MD5 eeff93978ddceaa791aa5a2cc75e05e9
BLAKE2b-256 4ac054d0180e258fc6b0991a88f80e23dbabb186beb9605abe2c2a914906646e

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.6-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.6-cp313-cp313-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 68afc5c50a111759807436ae6da452a388379fe5feda539185908a6edd0f0817
MD5 dd855703ff058c1ad5209aede561c7e7
BLAKE2b-256 f2a3569890db361fb1fbbc4736c712c29a0b5962c99799d05513d37f1a3f8849

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.6-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 05f9c19411084f803d3ea9907d8b69ab028ec83aab9c179cb5361f9db6bcd89f
MD5 0c5206c1067c031b16014228e3a0cc8a
BLAKE2b-256 f72a7cc6cc26e396fbe389af94cb3fc7da4419602006e7c13f0184414ba18303

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 50a602f95c748ffdc44cc2696eb76913668a3e3da06a8da910f6aefdaf0ff931
MD5 29201cf9d6543742b8d4e51ebe54798c
BLAKE2b-256 3ca5db136fd0f737e850ed2d675a7419652cc168ac71ee23c09285bd243e9f3b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 56c66adc3da7a315920c9f9033f9c47fa9819d2c8c06e8caf578be023015fb59
MD5 37fb9711c7da46437e0ca6bafe3c0062
BLAKE2b-256 3fe8beafb733f6387c9bc48a3de7e83044c7f7d69a5e83364e508dadc04ca5ca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp312-cp312-win32.whl
Algorithm Hash digest
SHA256 4cfb84470e2e410e0adc7e0d006719b38fc1c44d6e163dc4419fda415c39f3e9
MD5 48646536e363fc9d473fa7175ba08cd4
BLAKE2b-256 f9475168bbb91c46d02c51f9acd5395b505219d0f998d9a958d960fbb78b9c6b

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.6-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.6-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 324e34f8fc7d5444be329993bba11c80813ea42c58e98f4e3b81fc06c502f0fd
MD5 93cdfd394dd0114377dabc9957cbe5da
BLAKE2b-256 80ac378b8d04f834869b0d59891dc1066221c34584871284b1bbef819561aee1

See more details on using hashes here.

File details

Details for the file videosdk_conversational_graph-0.0.6-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 d2efe4a4d112851514f53d7095f013f4659970f40d55b3a0e8eabb6eff6779f4
MD5 2adf42d424aaa76ceda2f75e5b755adb
BLAKE2b-256 87e991d42be6aa32ad72b0472c6311bc45b2467f715ee0c84210e03fbf65fb2b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for videosdk_conversational_graph-0.0.6-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 47419085f1efb3c43b89aefac40d121ce70e3b733a5b648b47ee21536d020503
MD5 bb108be24d9d24c8b2284741208b6d9e
BLAKE2b-256 3d4639bcebf770870c0748e841169c9da611f79b9a7fe7a649781992605cc7e9

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