Compare commits

...
Author SHA1 Message Date
William FH 1282ff0332 Merge branch 'main' into wfh/cli_from_module 2025-03-24 12:25:55 -07:00
Eugene Yurtsev addb491cfd sdk: allow specifying run time headers in http client (#4000)
This PR only allows this in the HTTP client. 

I can follow up with a PR to allow throughout the entire API.

The use case is to allow instantiating the client once (w/ a single connection pool), but allowing changing api keys and any other headers at run time
2025-03-24 14:47:35 -04:00
Eugene Yurtsev c84f35eff5 add langmanus to prebuilt (#3999) 2025-03-24 13:26:53 -04:00
Eugene Yurtsev f178e4205f docs: add xxhash explicitly to docs pyproject.toml (#3998)
It's not getting picked up from the dev requirements for some reason.
2025-03-24 12:58:33 -04:00
William Fu-Hinthorn 8cc3ac189e Support for python -m langgraph 2025-03-21 13:29:00 -07:00
5 changed files with 1639 additions and 1986 deletions

No files matched your search

@@ -36,3 +36,6 @@ packages:
- name: "langgraph-reflection"
repo: "langchain-ai/langgraph-reflection"
description: "LangGraph agent that runs a reflection step."
- name: "langmanus"
repo: "langmanus/langmanus"
description: "A community-driven AI automation framework that builds upon the incredible work of the open source community. Our goal is to combine language models with specialized tools for tasks like web search, crawling, and Python code execution, while giving back to the community that made this possible."
+1512 -1955
View File
File diff suppressed because it is too large. Load diff
+1
View File
@@ -10,6 +10,7 @@ readme = "README.md"
python = "^3.10"
aiohappyeyeballs = "2.4.3"
hub = "^3.0.1"
xxhash = "^3.5.0"
[tool.poetry.group.docs.dependencies]
langgraph = { path = "../libs/langgraph/", develop = true }
+30
View File
@@ -0,0 +1,30 @@
try:
import sys
from langgraph_cli.cli import cli
except ImportError:
# Provide more detailed error message with installation instructions
error_message = (
"\nError: langgraph_cli package not found.\n\n"
"This could be due to one of the following reasons:\n"
"1. You haven't installed the CLI package\n"
"2. Your virtual environment doesn't have the package installed\n"
"3. There's a path issue with your Python environment\n\n"
"To fix this, try one of the following solutions:\n"
"- Install the CLI package: pip install langgraph-cli\n"
"- If you're using a virtual environment, activate it first\n"
"- Use the standalone CLI directly by running: langgraph\n\n"
"For more help, visit: https://github.com/langchain-ai/langgraph/tree/main/libs/cli"
)
raise ImportError(error_message)
try:
cli()
except Exception as e:
# Catch any exceptions that might occur when running the CLI
print(f"\nError occurred while running langgraph CLI: {str(e)}")
print(
"If this problem persists, please report it at: https://github.com/langchain-ai/langgraph/issues"
)
sys.exit(1)
+93 -31
View File
@@ -208,9 +208,15 @@ class HttpClient:
def __init__(self, client: httpx.AsyncClient) -> None:
self.client = client
async def get(self, path: str, *, params: Optional[QueryParamTypes] = None) -> Any:
async def get(
self,
path: str,
*,
params: Optional[QueryParamTypes] = None,
headers: Optional[dict[str, str]] = None,
) -> Any:
"""Send a GET request."""
r = await self.client.get(path, params=params)
r = await self.client.get(path, params=params, headers=headers)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -222,13 +228,22 @@ class HttpClient:
raise e
return await adecode_json(r)
async def post(self, path: str, *, json: Optional[dict]) -> Any:
async def post(
self,
path: str,
*,
json: Optional[dict],
headers: Optional[dict[str, str]] = None,
) -> Any:
"""Send a POST request."""
if json is not None:
headers, content = await aencode_json(json)
request_headers, content = await aencode_json(json)
else:
headers, content = {}, b""
r = await self.client.post(path, headers=headers, content=content)
request_headers, content = {}, b""
# Merge headers, with runtime headers taking precedence
if headers:
request_headers.update(headers)
r = await self.client.post(path, headers=request_headers, content=content)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -240,10 +255,14 @@ class HttpClient:
raise e
return await adecode_json(r)
async def put(self, path: str, *, json: dict) -> Any:
async def put(
self, path: str, *, json: dict, headers: Optional[dict[str, str]] = None
) -> Any:
"""Send a PUT request."""
headers, content = await aencode_json(json)
r = await self.client.put(path, headers=headers, content=content)
request_headers, content = await aencode_json(json)
if headers:
request_headers.update(headers)
r = await self.client.put(path, headers=request_headers, content=content)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -255,10 +274,14 @@ class HttpClient:
raise e
return await adecode_json(r)
async def patch(self, path: str, *, json: dict) -> Any:
async def patch(
self, path: str, *, json: dict, headers: Optional[dict[str, str]] = None
) -> Any:
"""Send a PATCH request."""
headers, content = await aencode_json(json)
r = await self.client.patch(path, headers=headers, content=content)
request_headers, content = await aencode_json(json)
if headers:
request_headers.update(headers)
r = await self.client.patch(path, headers=request_headers, content=content)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -270,9 +293,15 @@ class HttpClient:
raise e
return await adecode_json(r)
async def delete(self, path: str, *, json: Optional[Any] = None) -> None:
async def delete(
self,
path: str,
*,
json: Optional[Any] = None,
headers: Optional[dict[str, str]] = None,
) -> None:
"""Send a DELETE request."""
r = await self.client.request("DELETE", path, json=json)
r = await self.client.request("DELETE", path, json=json, headers=headers)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -290,14 +319,18 @@ class HttpClient:
*,
json: Optional[dict] = None,
params: Optional[QueryParamTypes] = None,
headers: Optional[dict[str, str]] = None,
) -> AsyncIterator[StreamPart]:
"""Stream results using SSE."""
headers, content = await aencode_json(json)
headers["Accept"] = "text/event-stream"
headers["Cache-Control"] = "no-store"
request_headers, content = await aencode_json(json)
request_headers["Accept"] = "text/event-stream"
request_headers["Cache-Control"] = "no-store"
# Add runtime headers with precedence
if headers:
request_headers.update(headers)
async with self.client.stream(
method, path, headers=headers, content=content, params=params
method, path, headers=request_headers, content=content, params=params
) as res:
# check status
try:
@@ -2447,9 +2480,15 @@ class SyncHttpClient:
def __init__(self, client: httpx.Client) -> None:
self.client = client
def get(self, path: str, *, params: Optional[QueryParamTypes] = None) -> Any:
def get(
self,
path: str,
*,
params: Optional[QueryParamTypes] = None,
headers: Optional[dict[str, str]] = None,
) -> Any:
"""Send a GET request."""
r = self.client.get(path, params=params)
r = self.client.get(path, params=params, headers=headers)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -2461,13 +2500,21 @@ class SyncHttpClient:
raise e
return decode_json(r)
def post(self, path: str, *, json: Optional[dict]) -> Any:
def post(
self,
path: str,
*,
json: Optional[dict],
headers: Optional[dict[str, str]] = None,
) -> Any:
"""Send a POST request."""
if json is not None:
headers, content = encode_json(json)
request_headers, content = encode_json(json)
else:
headers, content = {}, b""
r = self.client.post(path, headers=headers, content=content)
request_headers, content = {}, b""
if headers:
request_headers.update(headers)
r = self.client.post(path, headers=request_headers, content=content)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -2494,10 +2541,14 @@ class SyncHttpClient:
raise e
return decode_json(r)
def patch(self, path: str, *, json: dict) -> Any:
def patch(
self, path: str, *, json: dict, headers: Optional[dict[str, str]] = None
) -> Any:
"""Send a PATCH request."""
headers, content = encode_json(json)
r = self.client.patch(path, headers=headers, content=content)
request_headers, content = encode_json(json)
if headers:
request_headers.update(headers)
r = self.client.patch(path, headers=request_headers, content=content)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -2509,9 +2560,15 @@ class SyncHttpClient:
raise e
return decode_json(r)
def delete(self, path: str, *, json: Optional[Any] = None) -> None:
def delete(
self,
path: str,
*,
json: Optional[Any] = None,
headers: Optional[dict[str, str]] = None,
) -> None:
"""Send a DELETE request."""
r = self.client.request("DELETE", path, json=json)
r = self.client.request("DELETE", path, json=json, headers=headers)
try:
r.raise_for_status()
except httpx.HTTPStatusError as e:
@@ -2529,11 +2586,16 @@ class SyncHttpClient:
*,
json: Optional[dict] = None,
params: Optional[QueryParamTypes] = None,
headers: Optional[dict[str, str]] = None,
) -> Iterator[StreamPart]:
"""Stream the results of a request using SSE."""
headers, content = encode_json(json)
request_headers, content = encode_json(json)
request_headers["Accept"] = "text/event-stream"
request_headers["Cache-Control"] = "no-store"
if headers:
request_headers.update(headers)
with self.client.stream(
method, path, headers=headers, content=content, params=params
method, path, headers=request_headers, content=content, params=params
) as res:
# check status
try: