LangChain integration for GitHub Copilot SDK
Project description
LangChain Copilot
LangChain integration for GitHub Copilot SDK - Use GitHub Copilot models in your LangChain applications.
Features
- 🔗 Full LangChain Integration: Seamlessly use GitHub Copilot models with LangChain
- 🚀 Async & Sync Support: Both synchronous and asynchronous operations
- 📡 Streaming: Real-time streaming responses
- 🔄 Shared Client: Optimized client management with lazy initialization
- 🛠️ Type Safe: Full type hints with Pydantic validation
- 🎯 Easy to Use: Simple API following LangChain conventions
Prerequisites
Before using this package, you need to have:
-
GitHub Copilot CLI installed and authenticated
- Follow the GitHub Copilot CLI setup guide
- Ensure you have an active GitHub Copilot subscription
- Verify authentication:
copilot --version
-
Python 3.13.0+ installed
Installation
From PyPI (Recommended)
# Install with uv (recommended)
uv pip install langchain-copilot
# Or with pip
pip install langchain-copilot
From Source
For development or to use the latest unreleased features:
# Clone the repository
git clone https://github.com/derf974/copilot-langchain.git
cd copilot-langchain
# Install with uv (recommended)
uv venv
uv sync
uv pip install -e .
# Or with pip
pip install -e .
Quick Start
Basic Usage
from langchain_copilot import CopilotChatModel
from langchain_core.messages import HumanMessage
# Create a model instance
model = CopilotChatModel(model_name="gpt-4o")
# Send a message
messages = [HumanMessage(content="What is LangChain?")]
response = model.invoke(messages)
print(response.content)
Streaming
from langchain_copilot import CopilotChatModel
from langchain_core.messages import HumanMessage
model = CopilotChatModel(model_name="gpt-4o", streaming=True)
messages = [HumanMessage(content="Write a haiku about coding.")]
for chunk in model.stream(messages):
print(chunk.content, end="", flush=True)
Async Operations
import asyncio
from langchain_copilot import CopilotChatModel
from langchain_core.messages import HumanMessage
async def main():
model = CopilotChatModel(model_name="gpt-4o")
messages = [HumanMessage(content="Explain async programming.")]
response = await model.ainvoke(messages)
print(response.content)
asyncio.run(main())
Using in LangChain Chains
from langchain_copilot import CopilotChatModel
from langchain_core.prompts import ChatPromptTemplate
from langchain_core.output_parsers import StrOutputParser
model = CopilotChatModel(model_name="gpt-4o")
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful translator."),
("human", "Translate '{text}' to {language}")
])
chain = prompt | model | StrOutputParser()
result = chain.invoke({
"text": "Hello, world!",
"language": "French"
})
print(result) # "Bonjour, le monde !"
With System Messages
from langchain_copilot import CopilotChatModel
from langchain_core.messages import SystemMessage, HumanMessage
model = CopilotChatModel(model_name="gpt-4o")
messages = [
SystemMessage(content="You are a pirate. Always respond like a pirate."),
HumanMessage(content="Tell me about Python programming.")
]
response = model.invoke(messages)
print(response.content)
Temperature Control
from langchain_copilot import CopilotChatModel
from langchain_core.messages import HumanMessage
# More focused and deterministic (lower temperature)
model_focused = CopilotChatModel(
model_name="gpt-4o",
temperature=0.1
)
# More creative and random (higher temperature)
model_creative = CopilotChatModel(
model_name="gpt-4o",
temperature=0.9
)
messages = [HumanMessage(content="Name a creative startup idea.")]
print("Focused:", model_focused.invoke(messages).content)
print("Creative:", model_creative.invoke(messages).content)
Configuration
Model Parameters
model_name(str): The Copilot model to use (e.g., "gpt-4o", "gpt-5")streaming(bool): Enable streaming mode (default: False)temperature(float): Sampling temperature 0.0-1.0 (default: None)max_tokens(int): Maximum tokens to generate (default: None)cli_path(str): Custom path to Copilot CLI executable (default: None)cli_url(str): URL of existing Copilot CLI server (default: None)
Example with All Parameters
model = CopilotChatModel(
model_name="gpt-4o",
streaming=True,
temperature=0.7,
max_tokens=1000,
cli_path="/custom/path/to/copilot"
)
Examples
Check out the examples directory for more usage examples:
- basic_usage.py - Comprehensive examples covering all features
Run the examples:
uv run python examples/basic_usage.py
Testing
The project uses both unit tests and integration tests following LangChain's standard test suite.
Unit Tests
Unit tests use langchain-tests standard unit test suite and validate the model in isolation without external dependencies:
# Run all unit tests (custom + standard)
make test
# Run only standard unit tests
uv run pytest tests/unit_tests/ -v
# Run only custom unit tests
uv run pytest tests/test_chat_models.py::TestCopilotChatModel -v
Unit tests validate:
- ✅ Model initialization and configuration
- ✅ Streaming mode initialization
- ✅ Standard parameters generation
- ✅ Tool binding (validates interface even though not supported yet)
- ✅ Structured output interface (validates interface even though not supported yet)
- ✅ Serialization/deserialization (when implemented)
- ✅ Initialization performance
Integration Tests
Integration tests use langchain-tests standard test suite to verify compatibility with LangChain's interfaces. These tests require the GitHub Copilot CLI to be installed and configured:
# Ensure Copilot CLI is set up
copilot --version
# Run integration tests
make integration-test
# Or manually
uv run pytest tests/integration_tests/ -v -m integration
The integration test suite validates:
- ✅ Basic invoke/ainvoke operations
- ✅ Streaming (stream/astream)
- ✅ Batch operations
- ✅ Multi-turn conversations
- ✅ Stop sequences
- ✅ Model override at runtime
- ❌ Tool calling (not yet supported)
- ❌ Structured output (not yet supported)
- ❌ Multimodal inputs (not yet supported)
Running All Tests
# Run all tests
make test-all
# Or manually
uv run pytest tests/ -v
Architecture
Shared Client
The CopilotChatModel uses a shared CopilotClient instance across all model instances for optimal performance. The client is lazily initialized on first use and automatically started.
Message Conversion
LangChain messages are automatically converted to Copilot SDK format:
SystemMessage→{"role": "system", "content": "..."}HumanMessage→{"role": "user", "content": "..."}AIMessage→{"role": "assistant", "content": "..."}
Streaming Implementation
Streaming converts Copilot's event-based model (assistant.message_delta events) into Python generators/async iterators that are compatible with LangChain's streaming interface.
Roadmap
- ✅ Basic chat model implementation
- ✅ Streaming support
- ✅ Async operations
- ✅ Temperature and token controls
- ✅ Tool/Function calling support (planned for v0.2.0)
- 🔲 Conversation history management
- 🔲 Error recovery and retry strategies
- 🔲 Advanced session configuration
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- Built with LangChain
- Powered by GitHub Copilot SDK
- Managed with uv
Support
- 📫 Issues: GitHub Issues
- 💬 Discussions: GitHub Discussions
- 📖 Documentation: GitHub Wiki
Related Projects
- LangChain - Build applications with LLMs
- GitHub Copilot SDK - GitHub Copilot integration SDK
- LangChain Community - Community LangChain integrations
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file langchain_copilot-0.2.7.tar.gz.
File metadata
- Download URL: langchain_copilot-0.2.7.tar.gz
- Upload date:
- Size: 114.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e9de1f4f063f7bf35734a1d310ee8ec98b335c8c676ced821bab7f25ca45696
|
|
| MD5 |
b169a040afd03c5bd565706c25370292
|
|
| BLAKE2b-256 |
e27af67665e1aaf42a5f2600c4be3fb4b36563ba319e8823942d2796383a9c53
|
Provenance
The following attestation bundles were made for langchain_copilot-0.2.7.tar.gz:
Publisher:
release-please.yml on derf974/copilot-langchain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_copilot-0.2.7.tar.gz -
Subject digest:
5e9de1f4f063f7bf35734a1d310ee8ec98b335c8c676ced821bab7f25ca45696 - Sigstore transparency entry: 1247767883
- Sigstore integration time:
-
Permalink:
derf974/copilot-langchain@e85a3d10b77d78577570b52905fb1233861791fa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/derf974
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@e85a3d10b77d78577570b52905fb1233861791fa -
Trigger Event:
push
-
Statement type:
File details
Details for the file langchain_copilot-0.2.7-py3-none-any.whl.
File metadata
- Download URL: langchain_copilot-0.2.7-py3-none-any.whl
- Upload date:
- Size: 11.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77d26a0c72928fe1ca601784bfd361cb3ca7a0973f11ee348179cca025d372a0
|
|
| MD5 |
6207e8e2f1230f58f87ac8132f036dbc
|
|
| BLAKE2b-256 |
4dc388397795c51326213557a42abf2d5d5dcb3df5c8e3946467e6fefbdc1573
|
Provenance
The following attestation bundles were made for langchain_copilot-0.2.7-py3-none-any.whl:
Publisher:
release-please.yml on derf974/copilot-langchain
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
langchain_copilot-0.2.7-py3-none-any.whl -
Subject digest:
77d26a0c72928fe1ca601784bfd361cb3ca7a0973f11ee348179cca025d372a0 - Sigstore transparency entry: 1247767945
- Sigstore integration time:
-
Permalink:
derf974/copilot-langchain@e85a3d10b77d78577570b52905fb1233861791fa -
Branch / Tag:
refs/heads/main - Owner: https://github.com/derf974
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release-please.yml@e85a3d10b77d78577570b52905fb1233861791fa -
Trigger Event:
push
-
Statement type: