Skip to main content

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.

Release files for ascend-langchain 2.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ascend-langchain 2.0.1
File Size Uploaded
ascend_langchain-2.0.1.tar.gz 17.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for ascend-langchain 2.0.1
File Interpreter ABI Platform
ascend_langchain-2.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 33.6 kB

Release files / ascend_langchain-2.0.1.tar.gz

Download URL ascend_langchain-2.0.1.tar.gz
Size 17.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b2626d8086d1869ef371cada4a6e631a21b3d174e1ddb7f658e436948bc704d7
BLAKE2b-256 checksum
How to use checksums
4fab928ea9d33a92f890903ce3ac68187442de6bdd31ef5e08f99bbe37efb16a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release files / ascend_langchain-2.0.1-py3-none-any.whl

Download URL ascend_langchain-2.0.1-py3-none-any.whl
Size 16.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
122b2c96cba4169358a6c5e4db7217a7db853f54ddbecf104e866f8ebfa00108
BLAKE2b-256 checksum
How to use checksums
3625c361874dd3a91c929e5907c932d0efd3140edbd5f49fb5e1423660f0f59f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.1

Release history Release notifications | RSS feed

This release

2.0.1 This release

2 release files

2.0.0

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page