Skip to main content
pypi version
Pica LangChain Banner
Pica’s ToolKit provides enterprise-grade integration capabilities for AI agents built with LangChain. Give your agents intelligent access to 150+ third-party integrations with built-in authentication, error handling, and Pica’s knowledge base.

pica-langchain on PyPI

Install the Python SDK to unlock powerful tools for LangChain

Prerequisites

Before installing ToolKit, you’ll need:
  1. Pica Account - Free account for managing integrations
  2. Pica API Key - API key from your Pica dashboard
  3. LangChain - Installed in your Python project
  4. LLM Provider - API key from OpenAI, Anthropic, or your chosen provider

Installation

Install the Pica LangChain SDK:
pip install pica-langchain

Quick Start

1

Set environment variables

Configure your API keys as environment variables:
export PICA_SECRET="your-pica-secret"
export OPENAI_API_KEY="your-openai-api-key"
2

Connect integrations

Go to the Connections page and connect integrations (e.g., Gmail, Slack, Salesforce). You’ll need at least one connection for your agent to interact with.
3

Create your first agent

Create a LangChain agent with Pica tools:
import os
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions

# Initialize Pica client
pica_client = PicaClient(
    secret=os.environ["PICA_SECRET"],
    options=PicaClientOptions(
        connectors=["*"]  # Access all connected integrations
    )
)
pica_client.initialize()

# Create LLM
llm = ChatOpenAI(temperature=0, model="gpt-4.1")

# Create agent with Pica tools
agent = create_pica_agent(
    client=pica_client,
    llm=llm,
    agent_type=AgentType.OPENAI_FUNCTIONS,
)

# Execute
result = agent.invoke({
    "input": "What connections do I have access to?"
})

print(result)

Configuration

PicaClientOptions

Configure the Pica client with these options:
server_url
str
default:"https://api.picaos.com"
URL for self-hosted Pica server. Use this if you’re running your own instance of Pica.
options=PicaClientOptions(
    server_url="https://my-pica-instance.com"
)
connectors
List[str]
default:"All connectors"
List of connection keys to filter by. Pass ["*"] to initialize all available connections, or specify exact connection keys. If empty, no connections will be initialized.
# Enable all connections
connectors=["*"]

# Enable specific connections
connectors=[
    "live::gmail::default::abc123",
    "live::slack::default::def456"
]
actions
List[str]
default:"All actions"
List of action IDs to filter by. Set to ["*"] for all actions, or specify individual action IDs from the available actions table.
# Enable all actions
actions=["*"]

# Enable specific actions
actions=["conn_mod_def::GGSNOTZxFUU::ZWXBuJboTpS3Q_U06pF8gA"]
permissions
Literal['read', 'write', 'admin']
default:"admin"
Permission level to filter actions by:
  • "read" - Only GET requests (read-only access)
  • "write" - POST, PUT, PATCH requests (create/update operations)
  • "admin" - All HTTP methods including DELETE
permissions="read"  # Read-only agent
identity
str
Filter connections by a specific identifier (e.g., user ID, team ID). Use with identity_type for multi-tenant applications.
identity="user_123"
identity_type
Literal['user', 'team', 'project', 'organization']
Filter connections by identity type. Works with the identity parameter.
identity="user_123",
identity_type="user"
authkit
bool
default:"False"
If True, the SDK will use AuthKit to prompt users to connect platforms they don’t currently have access to.
authkit=True

create_pica_agent

Customize agent creation with these parameters:
client
PicaClient
required
Initialized Pica client instance. Must be created and initialized before passing to the agent.
pica_client = PicaClient(secret=os.environ["PICA_SECRET"])
pica_client.initialize()
llm
BaseLanguageModel
required
LangChain LLM to use for the agent. Can be any LangChain-compatible language model.
llm = ChatOpenAI(temperature=0, model="gpt-5")
agent_type
AgentType
default:"OPENAI_FUNCTIONS"
Type of LangChain agent to create. See LangChain documentation for available types.
agent_type=AgentType.OPENAI_FUNCTIONS
verbose
bool
default:"False"
Whether to print verbose logs during agent execution.
verbose=True
system_prompt
str
Custom system prompt to append to the default Pica system prompt.
system_prompt="You are a helpful sales assistant."
tools
List[BaseTool]
Additional LangChain tools to include alongside Pica tools.
tools=[my_custom_tool, another_tool]
return_intermediate_steps
bool
default:"False"
Whether to return the intermediate steps of the agent execution.
return_intermediate_steps=True

Usage Patterns

Basic Agent

The simplest setup with full access to integrations:
import os
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions

pica_client = PicaClient(
    secret=os.environ["PICA_SECRET"],
    options=PicaClientOptions(connectors=["*"])
)
pica_client.initialize()

llm = ChatOpenAI(temperature=0, model="gpt-4.1")

agent = create_pica_agent(
    client=pica_client,
    llm=llm,
    agent_type=AgentType.OPENAI_FUNCTIONS
)

result = agent.invoke({
    "input": "Send an email to hello@picaos.com with subject 'Test'"
})

Streaming Response

Enable streaming for real-time output:
Example
import os
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from langchain.callbacks.streaming_stdout import StreamingStdOutCallbackHandler
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions

pica_client = PicaClient(
    secret=os.environ["PICA_SECRET"],
    options=PicaClientOptions(connectors=["*"])
)
pica_client.initialize()

llm = ChatOpenAI(
    temperature=0,
    model="gpt-4.1",
    streaming=True,
    callbacks=[StreamingStdOutCallbackHandler()]
)

agent = create_pica_agent(
    client=pica_client,
    llm=llm,
    agent_type=AgentType.OPENAI_FUNCTIONS
)

for chunk in agent.stream({
    "input": "List three platforms available in Pica."
}):
    print(chunk)

With AuthKit

Enable AuthKit to prompt users to connect missing integrations:
Example
import os
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions

pica_client = PicaClient(
    secret=os.environ["PICA_SECRET"],
    options=PicaClientOptions(
        authkit=True,  # Enable AuthKit
        connectors=["*"]
    )
)
pica_client.initialize()

llm = ChatOpenAI(temperature=0, model="gpt-4.1")

agent = create_pica_agent(
    client=pica_client,
    llm=llm,
    agent_type=AgentType.OPENAI_FUNCTIONS,
    return_intermediate_steps=True
)

result = agent.invoke({
    "input": "Connect to google calendar"  # Triggers AuthKit if not connected
})

Multi-Tenant Agent

Filter connections by user identity:
Example
import os
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions

def create_user_agent(user_id: str):
    pica_client = PicaClient(
        secret=os.environ["PICA_SECRET"],
        options=PicaClientOptions(
            connectors=["*"],
            identity=user_id,
            identityType="user"
        )
    )
    pica_client.initialize()
    
    llm = ChatOpenAI(temperature=0, model="gpt-4.1")
    
    return create_pica_agent(
        client=pica_client,
        llm=llm,
        agent_type=AgentType.OPENAI_FUNCTIONS
    )

# Each user gets their own scoped agent
user_agent = create_user_agent("user_123")
result = user_agent.invoke({
    "input": "List my Gmail emails"
})

Example Workflows

  • GitHub Workflow
  • Airtable to GitHub
  • Sheets to Gmail
Star a GitHub repository and list your starred repos:
Example
from langchain_openai import ChatOpenAI
from langchain.agents import AgentType
from pica_langchain import PicaClient, create_pica_agent
from pica_langchain.models import PicaClientOptions

pica_client = PicaClient(
    secret=os.environ["PICA_SECRET"],
    options=PicaClientOptions(connectors=["*"])
)
pica_client.initialize()

llm = ChatOpenAI(temperature=0, model="gpt-4.1")

agent = create_pica_agent(
    client=pica_client,
    llm=llm,
    agent_type=AgentType.OPENAI_FUNCTIONS
)

result = agent.invoke({
    "input": (
        "Star the picahq/pica repo in github. "
        "Then, list 5 of the repositories that I have starred in github."
    )
})

print(f"Result: {result}")

Logging

The Pica LangChain SDK uses Python’s logging module. Set the log level using the PICA_LOG_LEVEL environment variable:
export PICA_LOG_LEVEL="debug"
Available log levels:
  • debug - Detailed debugging information
  • info - General information messages
  • warning - Warning messages
  • error - Error messages
  • critical - Critical error messages

Best Practices

Instead of connectors=["*"], specify exact connection keys for better performance:
options=PicaClientOptions(
    connectors=[
        "live::gmail::default::abc123",
        "live::slack::default::def456"
    ]
)
Use permission levels based on your use case:
  • "read" - For data retrieval agents
  • "write" - For agents that create/update data
  • "admin" - For full-access automation (use carefully)
Always filter by identity in multi-user applications:
options=PicaClientOptions(
    connectors=["*"],
    identity=user_id,
    identity_type="user"
)
Track API usage in your Pica dashboard and view request logs at Logs.

Troubleshooting

Problem: Agent reports no connections available.Solutions:
  • Verify you’ve connected integrations in the Pica dashboard
  • Check that connectors is set correctly (use ["*"] for all)
  • If using identity, ensure the identity value matches your connections
Problem: Agent finds actions but can’t execute them.Solutions:
  • Ensure connections have proper authentication
  • Check permissions level allows the required HTTP method
  • Verify the connection hasn’t expired (re-authenticate if needed)
  • Check for error messages in the agent’s response
Problem: Getting 401 or authentication errors.Solutions:
  • Verify PICA_SECRET environment variable is set correctly
  • Check API key is valid at Settings > API Keys
  • Ensure integrations are properly connected

Resources

I