惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

小众软件
小众软件
WordPress大学
WordPress大学
IT之家
IT之家
G
Google Developers Blog
Vercel News
Vercel News
阮一峰的网络日志
阮一峰的网络日志
博客园 - 三生石上(FineUI控件)
Engineering at Meta
Engineering at Meta
Martin Fowler
Martin Fowler
V
V2EX
爱范儿
爱范儿
Hugging Face - Blog
Hugging Face - Blog
Apple Machine Learning Research
Apple Machine Learning Research
B
Blog
V
Visual Studio Blog
有赞技术团队
有赞技术团队
I
InfoQ
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
月光博客
月光博客
J
Java Code Geeks
Stack Overflow Blog
Stack Overflow Blog
P
Proofpoint News Feed
云风的 BLOG
云风的 BLOG
雷峰网
雷峰网

LangChain Forum - Topics tagged python-help

Llama-server process has terminated: invalid argument --load-mode with Ollama client 0.32.6 and langchain-ollama 1.1.0 Langchain Certified Agent Engineer Exam - Exam link not received and no response Null-drift: A bare-metal O(1) Memory Store for continuous LangGraph agents Clarification needed: Assistant config vs context and graph initialization Proposal: a small local helper for readable run traces via PR Proxy Authentication Required 407 What is the right way to dynamically create and run a graph? Re-Implement claude code's dynamic workflow using langchian & deepagents How to define a correct state for multi-agent system Response Format Groq Model Pydantic I hope to get some recommendations for practical skills Interrupt does not work correctly in LangGraph The Qwen3.6b model in fireworks through initchatmodel reporting hugely inflated tokens For parallel execution in Node, should i use the functional API? Potential Enhancement: Django-Managed PostgresSaver Pre-interrupt() code re-runs on resume — anti-pattern, or is there a sanctioned way to detect resume? Interrupt parallel branch execution Best practices for self-hosting LangGraph Server OSS without LangGraph keys Dynamically Enabling/Disabling Graphs in a LangGraph Server at Runtime LangGraph thread copy can take 12+ minutes: recommended production pattern? Will DeltaChannel be the default for AgentState.messages, or expected to stay opt-in? Proposal: additional docs for implementing custom DB checkpointers or a guide on generic base checkpointer Prompt_cache_retention: '24h' supported in langchain agents and where to provide it, inside invoke or while creating client? Could RAG pipelines realistically cause deployment timeouts, is Render suitable for first-time RAG deployments? How do I use langchain_postgres' init_vectorstore_table correctly? Proposal: Graph-wide default error handler for StateGraph (fallback for nodes without error_handler) Support timedelta for CachePolicy.ttl, consistent with TimeoutPolicy Anyone confirms this issue that deepagent ui streaming is disturb by update in deepagent or bug issue Best Stack for Building AI Applications Seeking help regarding the connection between Websocket and tool calls
Hosting an agent server on Heroku
@alexk Alex · 2026-04-18 · via LangChain Forum - Topics tagged python-help

I’m trying to host an agent on Heroku as an Agent Server.

I’ve been following this guide so far: Self-host standalone servers - Docs by LangChain

According to this, it needs access to a Postgres DB and Redis Store.

And on Heroku, I use the container registry as I figure that using Heroku’s build-system where you just push to their repo won’t work: Container Registry & Runtime (Docker Deploys) | Heroku Dev Center

One major problem is that the Langgraph server expects DATABASE_URIand REDIS_URIas environment variables. Heroku though sets these by itself as DATABASE_URL and REDIS_URL and we can’t change them, and the connection strings can be rotated by Heroku anytime.

Hence, just duplicating these variables and copying over the connection strings won’t work either (not long term, at least).

So I wondered if there’s a way to either configure Langgraph to use different variables (looking into langgraph_api/config.py it doesn’t seem like it’s possible) - or if I can set the variables somewhere else at runtime, when the docker container starts up or something?

I’ve also seen these here, maybe this helps? If so, where to define these vars and how do I set them to my DATABASE_URL from the Heroku environment?

Here’s my agent.py file - we also see that it loads another DATABASE_URL but that’s the one containing production data which the agent is supposed to be answering questions about.

import os
from datetime import datetime, timedelta

import dotenv
import numpy as np
import pandas as pd
from langchain.agents import create_agent
from langchain_community.agent_toolkits import SQLDatabaseToolkit
from langchain_community.utilities import SQLDatabase
from langgraph.checkpoint.memory import MemorySaver
from langchain_experimental.tools import PythonREPLTool
from langchain_experimental.utilities import PythonREPL
from langchain_openai import ChatOpenAI

from system_prompts import SQL_AGENT_PROMPT

dotenv.load_dotenv(override=False)

# Use LM Studio for local models or OpenAI for cloud
USE_LOCAL = os.getenv("USE_LOCAL", "false").lower() == "true"
# Disable checkpointer for langgraph server (enabled by default)
DISABLE_CHECKPOINTER = os.getenv("DISABLE_CHECKPOINTER", "false").lower() == "true"

# just for local hosting
if USE_LOCAL:
    model = ChatOpenAI(
        # Model name doesn't matter for LM Studio
        model=os.getenv("LOCAL_MODEL", "local-model"),
        temperature=0,
        streaming=True,
        base_url=os.getenv("LOCAL_BASE_URL", "http://localhost:1234/v1"),
        # LM Studio doesn't require API key
        api_key="not-needed",
    )
else:
    model = ChatOpenAI(model="gpt-5.1", temperature=0, streaming=True)


# was used for former deployment, might be obsolete
def normalize_db_uri(uri: str) -> str:
    """
    Normalize database connection URIs.
    - Convert 'postgres://' (Heroku) to 'postgresql://' (SQLAlchemy)
    """
    if not uri:
        return uri
    if uri.startswith("postgres://"):
        return uri.replace("postgres://", "postgresql://", 1)
    return uri


database_url = os.getenv("DATABASE_URL")
database_url = normalize_db_uri(database_url)

db = SQLDatabase.from_uri(database_url)

toolkit = SQLDatabaseToolkit(db=db, llm=model)

tools = [tool for tool in toolkit.get_tools() if
         tool.name != "sql_db_query_checker"]

# Add Python REPL tool for code execution with restricted globals
# Create Python REPL with restricted globals
python_repl_instance = PythonREPL(
    _globals={
        "pd": pd,
        "pandas": pd,
        "np": np,
        "numpy": np,
        "datetime": datetime,
        "timedelta": timedelta,
    }
)

# Create the tool with custom description
python_repl = PythonREPLTool(python_repl=python_repl_instance)
python_repl.description = (
    "A Python shell for executing code. Use this to process data, "
    "perform calculations, filter results, or do multi-step analysis. "
    "Input should be valid Python code. Available libraries: pandas (pd), "
    "numpy (np), datetime. Results from SQL queries can be converted to "
    "DataFrames for processing."
)
tools.append(python_repl)

system_prompt = SQL_AGENT_PROMPT.format(
    dialect=db.dialect,
    top_k=5,
)

checkpointer = None if DISABLE_CHECKPOINTER else MemorySaver()

agent = create_agent(
    model, tools, system_prompt=system_prompt, checkpointer=checkpointer
)