By Sagar Shankaran, Founder of CallSphere
Master Python dependency management for AI projects using Poetry, uv, and virtual environments with reproducible builds, lock files, and Docker integration strategies.
Key takeaways
AI projects have some of the most complex dependency trees in software. A typical agent application depends on an LLM SDK, a vector database client, a web framework, and dozens of transitive dependencies — many with strict version requirements. Without proper environment management, you get "works on my machine" failures, broken deployments, and hours spent debugging version conflicts.
The Python ecosystem has evolved rapidly in this area. pip and requirements.txt are no longer sufficient for professional AI projects. Modern tools like Poetry and uv provide lock files, dependency resolution, and virtual environment management in a single workflow.
Every Python project should use a virtual environment. No exceptions.
flowchart LR
INPUT(["User intent"])
PARSE["Parse plus<br/>classify"]
PLAN["Plan and tool<br/>selection"]
AGENT["Agent loop<br/>LLM plus tools"]
GUARD{"Guardrails<br/>and policy"}
EXEC["Execute and<br/>verify result"]
OBS[("Trace and metrics")]
OUT(["Outcome plus<br/>next action"])
INPUT --> PARSE --> PLAN --> AGENT --> GUARD
GUARD -->|Pass| EXEC --> OUT
GUARD -->|Fail| AGENT
AGENT --> OBS
style AGENT fill:#4f46e5,stroke:#4338ca,color:#fff
style GUARD fill:#f59e0b,stroke:#d97706,color:#1f2937
style OBS fill:#ede9fe,stroke:#7c3aed,color:#1e1b4b
style OUT fill:#059669,stroke:#047857,color:#fff
# Built-in venv module
python -m venv .venv
source .venv/bin/activate
# Verify isolation
which python # should show .venv/bin/python
pip list # should show minimal packages
Virtual environments isolate your project's dependencies from the system Python and from other projects. Without them, installing openai==1.50 for one project can break another that requires openai==1.30.
Hear it before you finish reading
Talk to a live CallSphere AI voice agent for IT support in your browser — 60 seconds, no signup.
Poetry handles dependency management, virtual environments, and packaging in one tool. It uses a pyproject.toml for configuration and a poetry.lock for reproducible installs.
# Install Poetry
curl -sSL https://install.python-poetry.org | python3 -
# Create a new AI project
poetry new my-agent-project
cd my-agent-project
# Add dependencies
poetry add openai pydantic fastapi
poetry add anthropic --optional # optional dependency group
# Add dev dependencies
poetry add --group dev pytest mypy ruff
# Install everything from lock file (exact versions)
poetry install
The pyproject.toml becomes the single source of truth for your project.
[tool.poetry]
name = "my-agent-project"
version = "0.1.0"
python = "^3.11"
[tool.poetry.dependencies]
python = "^3.11"
openai = "^1.50"
pydantic = "^2.7"
fastapi = "^0.111"
uvicorn = {version = "^0.30", extras = ["standard"]}
[tool.poetry.group.dev.dependencies]
pytest = "^8.0"
pytest-asyncio = "^0.23"
mypy = "^1.10"
ruff = "^0.5"
uv is a Rust-based Python package manager that is dramatically faster than pip and Poetry. It resolves and installs dependencies in seconds instead of minutes.
# Install uv
curl -LsSf https://astral.sh/uv/install.sh | sh
# Create a project with uv
uv init my-agent-project
cd my-agent-project
# Add dependencies (generates pyproject.toml and uv.lock)
uv add openai pydantic fastapi
uv add --dev pytest mypy ruff
# Install from lock file
uv sync
# Run scripts without activating the venv
uv run python main.py
uv run pytest
Speed comparison for a typical AI project with 50 dependencies:
Lock files pin every transitive dependency to an exact version. Without them, pydantic>=2.0 might install 2.7 on your machine and 2.9 on the server, introducing subtle behavioral differences.
# Poetry generates poetry.lock automatically
poetry lock
# uv generates uv.lock automatically
uv lock
# Always commit lock files to version control
git add poetry.lock # or uv.lock
git commit -m "Update dependency lock file"
AI application Docker images should use multi-stage builds to keep images small and leverage caching for dependencies.
Still reading? Stop comparing — try CallSphere live.
See the IT support AI agent handle a real call — complete, industry-specific, and live in your browser. No signup.
# Poetry-based Dockerfile
FROM python:3.11-slim AS builder
RUN pip install poetry==1.8.0
WORKDIR /app
COPY pyproject.toml poetry.lock ./
RUN poetry config virtualenvs.create false \
&& poetry install --no-root --only main
FROM python:3.11-slim
WORKDIR /app
COPY --from=builder /usr/local/lib/python3.11/site-packages /usr/local/lib/python3.11/site-packages
COPY --from=builder /usr/local/bin /usr/local/bin
COPY . .
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
# uv-based Dockerfile (simpler and faster)
FROM python:3.11-slim
COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
WORKDIR /app
COPY pyproject.toml uv.lock ./
RUN uv sync --frozen --no-dev
COPY . .
CMD ["uv", "run", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]
AI libraries sometimes require specific Python versions. Use pyenv to manage multiple installations.
# Install specific Python versions
pyenv install 3.11.9
pyenv install 3.12.4
# Set project-specific version
cd my-agent-project
pyenv local 3.11.9 # creates .python-version file
# uv respects .python-version automatically
uv sync # uses Python 3.11.9
For new projects, uv is the recommended choice. It is significantly faster, produces compatible pyproject.toml files, and has reached maturity with lock file support and workspace features. Poetry remains a solid choice if your team is already invested in it or if you need its packaging and publishing features.
Never. Add .venv/ to your .gitignore. The lock file is what guarantees reproducibility. Anyone can recreate the exact environment by running poetry install or uv sync from the lock file.
Use Docker containers to isolate system-level dependencies. Some AI libraries require specific versions of CUDA, cuDNN, or system libraries that cannot coexist. Docker gives each project its own system environment. For development, use NVIDIA's base images that include the correct CUDA toolkit for your GPU workloads.
#Python #Poetry #Uv #DevOps #AgenticAI #LearnAI #AIEngineering

Written by
Sagar Shankaran· Founder, CallSphere
LinkedInSagar Shankaran is the founder of CallSphere, where he builds production AI voice and chat agents deployed across healthcare, hospitality, real estate, and home services. He writes about agentic AI, LLM engineering, and shipping voice agents that handle real calls in production.
See how AI voice agents work for your industry. Live demo available -- no signup required.
See how Circini's automated incident management pipeline turns alert emails into triaged Jira tickets using Snowflake Cortex AI, GPT-4.1, Airflow & MS Teams.
The 2026 desktop AI agent landscape — ServiceNow Project Arc, Anthropic Claude offerings, OpenAI agents, and Google Mariner. A buyer's map.
Step-by-step build of a working agent with the OpenAI Agents SDK — Agent class, tools, handoffs, tracing — plus an eval pipeline that catches regressions before merge.
An agentic-AI perspective on Anthropic Skills system, covering orchestration patterns, tool use, and how agent tooling fits production agent stacks.
Enterprise CIO Guide perspective on Comet's general-availability launch put an agentic browser in front of millions of consumers, and it works better than the demos suggested.
Enterprise CIO Guide perspective on Harvey AI's enterprise rollout numbers show legal agents have moved past the pilot stage at AmLaw 100 firms.
© 2026 CallSphere Inc. All rights reserved.
Made within San Francisco
Watch how CallSphere handles real customer calls, schedules appointments, and processes payments — live.
Try Live DemoBook a DemoCalculate Your ROI