langchain-trigger-server 0.1.2__tar.gz → 0.1.5__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of langchain-trigger-server might be problematic. Click here for more details.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain-trigger-server
3
- Version: 0.1.2
3
+ Version: 0.1.5
4
4
  Summary: Generic event-driven triggers framework
5
5
  Project-URL: Homepage, https://github.com/langchain-ai/open-agent-platform
6
6
  Project-URL: Repository, https://github.com/langchain-ai/open-agent-platform
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.12
18
18
  Requires-Python: >=3.9
19
19
  Requires-Dist: fastapi>=0.100.0
20
20
  Requires-Dist: httpx>=0.24.0
21
+ Requires-Dist: langgraph-sdk>=0.2.6
21
22
  Requires-Dist: pydantic>=2.0.0
22
23
  Requires-Dist: python-jose[cryptography]>=3.3.0
23
24
  Requires-Dist: python-multipart>=0.0.6
@@ -9,6 +9,7 @@ from typing import Any, Callable, Dict, List, Optional
9
9
  import httpx
10
10
 
11
11
  from fastapi import FastAPI, HTTPException, Request, Depends
12
+ from langgraph_sdk import get_client
12
13
  from starlette.middleware.base import BaseHTTPMiddleware
13
14
  from starlette.responses import Response
14
15
 
@@ -92,6 +93,9 @@ class TriggerServer:
92
93
 
93
94
  self.langgraph_api_url = self.langgraph_api_url.rstrip("/")
94
95
 
96
+ # Initialize LangGraph SDK client
97
+ self.langgraph_client = get_client(url=self.langgraph_api_url)
98
+
95
99
  self.langchain_auth_client = None
96
100
  try:
97
101
  from langchain_auth import Client
@@ -523,12 +527,13 @@ class TriggerServer:
523
527
  }
524
528
 
525
529
  try:
526
- await self._invoke_agent(
530
+ success = await self._invoke_agent(
527
531
  agent_id=agent_id,
528
532
  user_id=registration["user_id"],
529
533
  input_data=agent_input,
530
534
  )
531
- agents_invoked += 1
535
+ if success:
536
+ agents_invoked += 1
532
537
  except Exception as e:
533
538
  logger.error(f"Error invoking agent {agent_id}: {e}", exc_info=True)
534
539
 
@@ -554,47 +559,40 @@ class TriggerServer:
554
559
  agent_id: str,
555
560
  user_id: str,
556
561
  input_data: Dict[str, Any],
557
- ) -> Dict[str, Any]:
558
- """Invoke LangGraph agent directly."""
559
- # Build headers using the custom function
560
- headers = await self.langgraph_headers_builder(
561
- user_id=user_id,
562
- api_key=self.langgraph_api_key,
563
- agent_id=agent_id
564
- )
565
-
566
- payload = {
567
- "input": input_data,
568
- "assistant_id": agent_id,
569
- "metadata": {
570
- "triggered_by": "langchain-triggers",
571
- "user_id": user_id,
572
- },
573
- }
574
-
575
- # Let LangGraph create a new thread automatically
576
- url = f"{self.langgraph_api_url}/runs"
577
-
562
+ ) -> bool:
563
+ """Invoke LangGraph agent using the SDK."""
578
564
  logger.info(f"Invoking LangGraph agent {agent_id} for user {user_id}")
579
565
 
580
- async with httpx.AsyncClient() as client:
581
- try:
582
- response = await client.post(
583
- url,
584
- json=payload,
585
- headers=headers,
586
- timeout=30.0,
587
- )
588
- response.raise_for_status()
589
-
590
- result = response.json()
591
- logger.info(f"Successfully invoked agent {agent_id}")
592
- return result
593
-
594
- except httpx.HTTPStatusError as e:
595
- logger.error(f"HTTP error invoking agent: {e.response.status_code} - {e.response.text}")
596
- raise
597
- except Exception as e:
566
+ try:
567
+ # Build headers using the custom function
568
+ headers = await self.langgraph_headers_builder(
569
+ user_id=user_id,
570
+ api_key=self.langgraph_api_key,
571
+ agent_id=agent_id
572
+ )
573
+
574
+ # Create a background run using the SDK
575
+ run = await self.langgraph_client.runs.create(
576
+ thread_id=None,
577
+ assistant_id=agent_id,
578
+ input=input_data,
579
+ metadata={
580
+ "triggered_by": "langchain-triggers",
581
+ "user_id": user_id,
582
+ },
583
+ headers=headers,
584
+ if_not_exists="create",
585
+ )
586
+
587
+ logger.info(f"Successfully invoked agent {agent_id}, run_id: {run['run_id']}, thread_id: {run['thread_id']}")
588
+ return True
589
+
590
+ except Exception as e:
591
+ # Handle 404s (agent not found) as warnings, not errors
592
+ if hasattr(e, 'response') and getattr(e.response, 'status_code', None) == 404:
593
+ logger.warning(f"Agent {agent_id} not found (404) - agent may have been deleted or moved")
594
+ return False
595
+ else:
598
596
  logger.error(f"Error invoking agent {agent_id}: {e}")
599
597
  raise
600
598
 
@@ -116,27 +116,7 @@ class TriggerDatabaseInterface(ABC):
116
116
  async def get_triggers_for_agent(self, agent_id: str) -> List[Dict[str, Any]]:
117
117
  """Get all trigger registrations linked to an agent."""
118
118
  pass
119
-
120
- @abstractmethod
121
- async def set_agent_trigger_links(
122
- self,
123
- agent_id: str,
124
- registration_ids: List[str],
125
- created_by: str
126
- ) -> bool:
127
- """Replace all trigger links for an agent (atomic operation)."""
128
- pass
129
-
130
- @abstractmethod
131
- async def replace_trigger_agent_links(
132
- self,
133
- registration_id: str,
134
- agent_ids: List[str],
135
- created_by: str
136
- ) -> bool:
137
- """Replace all agent links for a trigger (atomic operation)."""
138
- pass
139
-
119
+
140
120
  # ========== Helper Methods ==========
141
121
 
142
122
  @abstractmethod
@@ -277,68 +277,6 @@ class SupabaseTriggerDatabase(TriggerDatabaseInterface):
277
277
  logger.error(f"Error getting triggers for agent: {e}")
278
278
  return []
279
279
 
280
- async def set_agent_trigger_links(
281
- self,
282
- agent_id: str,
283
- registration_ids: List[str],
284
- created_by: str
285
- ) -> bool:
286
- """Replace all trigger links for an agent (atomic operation)."""
287
- try:
288
- # Delete existing links
289
- await self.client.table("agent_trigger_links").delete().eq("agent_id", agent_id).execute()
290
-
291
- # Create new links
292
- if registration_ids:
293
- links = [
294
- {
295
- "agent_id": agent_id,
296
- "registration_id": reg_id,
297
- "created_by": created_by
298
- }
299
- for reg_id in registration_ids
300
- ]
301
-
302
- response = self.client.table("agent_trigger_links").insert(links).execute()
303
- return bool(response.data)
304
-
305
- return True # Successfully cleared all links
306
-
307
- except Exception as e:
308
- logger.error(f"Error setting agent trigger links: {e}")
309
- return False
310
-
311
- async def replace_trigger_agent_links(
312
- self,
313
- registration_id: str,
314
- agent_ids: List[str],
315
- created_by: str
316
- ) -> bool:
317
- """Replace all agent links for a trigger (atomic operation)."""
318
- try:
319
- # Delete existing links
320
- await self.client.table("agent_trigger_links").delete().eq("registration_id", registration_id).execute()
321
-
322
- # Create new links
323
- if agent_ids:
324
- links = [
325
- {
326
- "agent_id": agent_id,
327
- "registration_id": registration_id,
328
- "created_by": created_by
329
- }
330
- for agent_id in agent_ids
331
- ]
332
-
333
- response = self.client.table("agent_trigger_links").insert(links).execute()
334
- return bool(response.data)
335
-
336
- return True # Successfully cleared all links
337
-
338
- except Exception as e:
339
- logger.error(f"Error replacing trigger agent links: {e}")
340
- return False
341
-
342
280
  # ========== Helper Methods ==========
343
281
 
344
282
  async def get_user_from_token(self, token: str) -> Optional[str]:
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "langchain-trigger-server"
7
- version = "0.1.2"
7
+ version = "0.1.5"
8
8
  description = "Generic event-driven triggers framework"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.9"
@@ -30,6 +30,7 @@ dependencies = [
30
30
  "httpx>=0.24.0",
31
31
  "python-multipart>=0.0.6",
32
32
  "python-jose[cryptography]>=3.3.0",
33
+ "langgraph-sdk>=0.2.6",
33
34
  ]
34
35
 
35
36
  [project.optional-dependencies]