Skip to main content

ASCEND governance integration for LangChain AI agents

Project description

ASCEND LangChain Integration

Enterprise-grade AI governance for LangChain agents and tools.

PyPI version Python 3.8+ License: MIT

Installation

pip install ascend-langchain

Quick Start

1. Wrap Existing Tools

The simplest way to add governance - wrap any LangChain tool:

from ascend_langchain import AscendToolWrapper
from langchain_community.tools import DuckDuckGoSearchRun

# Wrap existing tool with governance
search = AscendToolWrapper(
    tool=DuckDuckGoSearchRun(),
    action_type="web.search",
    risk_level="low"
)

# Use as normal - governance happens automatically
result = search.invoke("latest AI governance news")

2. Use Callback Handler

Automatic governance for all agent tool calls:

from ascend_langchain import AscendCallbackHandler
from langchain.agents import AgentExecutor

# Create callback handler
handler = AscendCallbackHandler(
    agent_id="customer-support-agent",
    agent_name="Customer Support Bot"
)

# Add to agent executor
executor = AgentExecutor(
    agent=agent,
    tools=tools,
    callbacks=[handler]
)

# All tool calls are now governed
result = executor.invoke({"input": "Help me with my order"})

3. Use Decorator

Simple function-level governance:

from ascend_langchain import governed

@governed(action_type="database.query", tool_name="postgresql", risk_level="high")
def query_database(query: str) -> list:
    return db.execute(query).fetchall()

# Governance check happens automatically
results = query_database("SELECT * FROM customers")

4. Create Governed Tools

Build governed tools from scratch:

from ascend_langchain import GovernedBaseTool

class DatabaseQueryTool(GovernedBaseTool):
    name = "query_database"
    description = "Execute SQL queries against the database"
    action_type = "database.query"
    tool_name = "postgresql"
    risk_level = "high"

    def _execute(self, query: str) -> str:
        return str(db.execute(query).fetchall())

# Use in LangChain agent
tool = DatabaseQueryTool()

Or use the factory function:

from ascend_langchain import create_governed_tool

sql_tool = create_governed_tool(
    name="sql_query",
    description="Execute SQL queries",
    func=lambda query: str(db.execute(query).fetchall()),
    action_type="database.query",
    tool_name="postgresql",
    risk_level="high"
)

Configuration

Environment Variables

export ASCEND_API_KEY="owkai_your_key_here"
export ASCEND_API_URL="https://api.owkai.app"  # Optional
export ASCEND_AGENT_ID="my-langchain-agent"   # Optional

Risk Levels

Level Description Default Behavior
low Read-only, non-sensitive Auto-approve
medium Write operations Evaluate policy
high Delete, modify critical Require review
critical Financial, PII access Require approval

Complete Example

import os
from langchain.agents import AgentExecutor, create_react_agent
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
from ascend_langchain import (
    AscendCallbackHandler,
    GovernedBaseTool,
    create_governed_tool
)

# Set API key
os.environ["ASCEND_API_KEY"] = "owkai_your_key_here"

# Create governed tools
class CustomerLookupTool(GovernedBaseTool):
    name = "customer_lookup"
    description = "Look up customer information by ID"
    action_type = "database.read"
    tool_name = "crm_database"
    risk_level = "medium"

    def _execute(self, customer_id: str) -> str:
        # Your actual lookup logic
        return f"Customer {customer_id}: John Doe, Premium tier"

# Create callback handler for automatic governance
handler = AscendCallbackHandler(
    agent_id="support-agent-prod",
    agent_name="Customer Support Agent"
)

# Set up agent
llm = ChatOpenAI(model="gpt-4", temperature=0)
tools = [CustomerLookupTool()]

prompt = PromptTemplate.from_template("""
You are a customer support assistant.

Tools: {tools}
Tool Names: {tool_names}

Question: {input}
{agent_scratchpad}
""")

agent = create_react_agent(llm, tools, prompt)
executor = AgentExecutor(
    agent=agent,
    tools=tools,
    callbacks=[handler],
    verbose=True
)

# Run agent - all tool calls are governed
result = executor.invoke({"input": "Look up customer 12345"})
print(result["output"])

Features

  • AscendToolWrapper: Wrap any existing LangChain tool
  • AscendCallbackHandler: Automatic governance for all agent actions
  • @governed decorator: Simple function-level governance
  • GovernedBaseTool: Base class for custom governed tools
  • create_governed_tool(): Factory function for quick tool creation
  • Full audit trail: All actions logged to ASCEND
  • Risk classification: Automatic risk-based policy enforcement
  • Fail-secure design: Deny by default on errors

Documentation

License

MIT License - see LICENSE for details.

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

ascend_langchain-2.0.1.tar.gz (17.4 kB view details)

Uploaded Source

Built Distribution

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

ascend_langchain-2.0.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file ascend_langchain-2.0.1.tar.gz.

File metadata

  • Download URL: ascend_langchain-2.0.1.tar.gz
  • Upload date:
  • Size: 17.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.1

File hashes

Hashes for ascend_langchain-2.0.1.tar.gz
Algorithm Hash digest
SHA256 b2626d8086d1869ef371cada4a6e631a21b3d174e1ddb7f658e436948bc704d7
MD5 f00e81f69aad6ea7451c8140ae653d9a
BLAKE2b-256 4fab928ea9d33a92f890903ce3ac68187442de6bdd31ef5e08f99bbe37efb16a

See more details on using hashes here.

File details

Details for the file ascend_langchain-2.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for ascend_langchain-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 122b2c96cba4169358a6c5e4db7217a7db853f54ddbecf104e866f8ebfa00108
MD5 f8fcdbc57d108056bf652beb609bbf1d
BLAKE2b-256 3625c361874dd3a91c929e5907c932d0efd3140edbd5f49fb5e1423660f0f59f

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