agent-api-server 2.1.7__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.
Files changed (52) hide show
  1. agent_api_server-2.1.7/PKG-INFO +130 -0
  2. agent_api_server-2.1.7/README.md +92 -0
  3. agent_api_server-2.1.7/agent_api_server/__init__.py +0 -0
  4. agent_api_server-2.1.7/agent_api_server/api/__init__.py +0 -0
  5. agent_api_server-2.1.7/agent_api_server/api/v1/__init__.py +0 -0
  6. agent_api_server-2.1.7/agent_api_server/api/v1/api.py +25 -0
  7. agent_api_server-2.1.7/agent_api_server/api/v1/config.py +57 -0
  8. agent_api_server-2.1.7/agent_api_server/api/v1/graph.py +59 -0
  9. agent_api_server-2.1.7/agent_api_server/api/v1/schema.py +57 -0
  10. agent_api_server-2.1.7/agent_api_server/api/v1/thread.py +563 -0
  11. agent_api_server-2.1.7/agent_api_server/cache/__init__.py +0 -0
  12. agent_api_server-2.1.7/agent_api_server/cache/redis_cache.py +385 -0
  13. agent_api_server-2.1.7/agent_api_server/callback_handler.py +18 -0
  14. agent_api_server-2.1.7/agent_api_server/client/css/styles.css +1202 -0
  15. agent_api_server-2.1.7/agent_api_server/client/favicon.ico +0 -0
  16. agent_api_server-2.1.7/agent_api_server/client/index.html +102 -0
  17. agent_api_server-2.1.7/agent_api_server/client/js/app.js +1499 -0
  18. agent_api_server-2.1.7/agent_api_server/client/js/index.umd.js +824 -0
  19. agent_api_server-2.1.7/agent_api_server/config_center/config_center.py +239 -0
  20. agent_api_server-2.1.7/agent_api_server/configs/__init__.py +3 -0
  21. agent_api_server-2.1.7/agent_api_server/configs/config.py +163 -0
  22. agent_api_server-2.1.7/agent_api_server/dynamic_llm/__init__.py +0 -0
  23. agent_api_server-2.1.7/agent_api_server/dynamic_llm/dynamic_llm.py +331 -0
  24. agent_api_server-2.1.7/agent_api_server/listener.py +530 -0
  25. agent_api_server-2.1.7/agent_api_server/log/__init__.py +0 -0
  26. agent_api_server-2.1.7/agent_api_server/log/formatters.py +122 -0
  27. agent_api_server-2.1.7/agent_api_server/log/logging.json +50 -0
  28. agent_api_server-2.1.7/agent_api_server/mcp_convert/__init__.py +0 -0
  29. agent_api_server-2.1.7/agent_api_server/mcp_convert/mcp_convert.py +375 -0
  30. agent_api_server-2.1.7/agent_api_server/memeory/__init__.py +0 -0
  31. agent_api_server-2.1.7/agent_api_server/memeory/postgres.py +233 -0
  32. agent_api_server-2.1.7/agent_api_server/register/__init__.py +0 -0
  33. agent_api_server-2.1.7/agent_api_server/register/register.py +65 -0
  34. agent_api_server-2.1.7/agent_api_server/service.py +354 -0
  35. agent_api_server-2.1.7/agent_api_server/service_hub/service_hub.py +233 -0
  36. agent_api_server-2.1.7/agent_api_server/service_hub/service_hub_test.py +700 -0
  37. agent_api_server-2.1.7/agent_api_server/shared/__init__.py +0 -0
  38. agent_api_server-2.1.7/agent_api_server/shared/ase.py +54 -0
  39. agent_api_server-2.1.7/agent_api_server/shared/base_model.py +103 -0
  40. agent_api_server-2.1.7/agent_api_server/shared/common.py +110 -0
  41. agent_api_server-2.1.7/agent_api_server/shared/decode_token.py +107 -0
  42. agent_api_server-2.1.7/agent_api_server/shared/detect_message.py +410 -0
  43. agent_api_server-2.1.7/agent_api_server/shared/get_model_info.py +491 -0
  44. agent_api_server-2.1.7/agent_api_server/shared/message.py +419 -0
  45. agent_api_server-2.1.7/agent_api_server/shared/util_func.py +372 -0
  46. agent_api_server-2.1.7/agent_api_server/sso_service/__init__.py +1 -0
  47. agent_api_server-2.1.7/agent_api_server/sso_service/sdk/__init__.py +1 -0
  48. agent_api_server-2.1.7/agent_api_server/sso_service/sdk/client.py +224 -0
  49. agent_api_server-2.1.7/agent_api_server/sso_service/sdk/credential.py +11 -0
  50. agent_api_server-2.1.7/agent_api_server/sso_service/sdk/encoding.py +22 -0
  51. agent_api_server-2.1.7/agent_api_server/sso_service/sso_service.py +177 -0
  52. agent_api_server-2.1.7/pyproject.toml +54 -0
@@ -0,0 +1,130 @@
1
+ Metadata-Version: 2.3
2
+ Name: agent-api-server
3
+ Version: 2.1.7
4
+ Summary: A Langgraph agent API server that implements Langgraph agent's web capabilities and can interact with chatbot
5
+ Author: zijie.zhang@advantech.com.cn
6
+ Requires-Python: >=3.10,<3.13
7
+ Classifier: Programming Language :: Python :: 3
8
+ Classifier: Programming Language :: Python :: 3.10
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: aiofiles (>=24.1.0,<25.0.0)
12
+ Requires-Dist: authlib (>=1.6.5)
13
+ Requires-Dist: cryptography (>=45.0.4,<46.0.0)
14
+ Requires-Dist: fastapi (>=0.117.0,<0.121.2)
15
+ Requires-Dist: fastmcp (>=2.13.0,<3.0.0)
16
+ Requires-Dist: langchain-community (==0.3.29)
17
+ Requires-Dist: langchain-core (==0.3.76)
18
+ Requires-Dist: langchain-openai (==0.3.33)
19
+ Requires-Dist: langchain-text-splitters (==0.3.11)
20
+ Requires-Dist: langfuse (>=3.14.5,<4.0.0)
21
+ Requires-Dist: langgraph (==0.6.11)
22
+ Requires-Dist: langgraph-checkpoint (>=3.0.1,<4.0.0)
23
+ Requires-Dist: langgraph-checkpoint-postgres (==3.0.0)
24
+ Requires-Dist: langgraph-prebuilt (==0.6.5)
25
+ Requires-Dist: langsmith (==0.4.28)
26
+ Requires-Dist: llm-sdk (==0.0.10)
27
+ Requires-Dist: model-manage-client (>=0.0.1.8,<0.0.2.0)
28
+ Requires-Dist: nats-py (>=2.11.0,<3.0.0)
29
+ Requires-Dist: psycopg-binary (>=3.2.9,<4.0.0)
30
+ Requires-Dist: psycopg-pool (>=3.2.6,<4.0.0)
31
+ Requires-Dist: pydantic-settings (>=2.9.1,<3.0.0)
32
+ Requires-Dist: redis (>=6.2.0,<7.0.0)
33
+ Requires-Dist: starlette (>=0.49.3,<0.50.0)
34
+ Requires-Dist: tenacity (>=9.1.2,<10.0.0)
35
+ Requires-Dist: xinference-client (>=1.8.0,<2.0.0)
36
+ Description-Content-Type: text/markdown
37
+
38
+ # agent_api_server
39
+
40
+
41
+
42
+ ## Getting started
43
+
44
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
45
+
46
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
47
+
48
+ ## Add your files
49
+
50
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
51
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
52
+
53
+ ```
54
+ cd existing_repo
55
+ git remote add origin https://gitlab.wise-paas.com/openai/agent_api_server.git
56
+ git branch -M main
57
+ git push -uf origin main
58
+ ```
59
+
60
+ ## Integrate with your tools
61
+
62
+ - [ ] [Set up project integrations](https://gitlab.wise-paas.com/openai/agent_api_server/-/settings/integrations)
63
+
64
+ ## Collaborate with your team
65
+
66
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
67
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
68
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
69
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
70
+ - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
71
+
72
+ ## Test and Deploy
73
+
74
+ Use the built-in continuous integration in GitLab.
75
+
76
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
77
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
78
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
79
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
80
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
81
+
82
+ ***
83
+
84
+ # Editing this README
85
+
86
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
87
+
88
+ ## Suggestions for a good README
89
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
90
+
91
+ ## Name
92
+ Choose a self-explaining name for your project.
93
+
94
+ ## Description
95
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
96
+
97
+ ## Badges
98
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
99
+
100
+ ## Visuals
101
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
102
+
103
+ ## Installation
104
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
105
+
106
+ ## Usage
107
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
108
+
109
+ ## Support
110
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
111
+
112
+ ## Roadmap
113
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
114
+
115
+ ## Contributing
116
+ State if you are open to contributions and what your requirements are for accepting them.
117
+
118
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
119
+
120
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
121
+
122
+ ## Authors and acknowledgment
123
+ Show your appreciation to those who have contributed to the project.
124
+
125
+ ## License
126
+ For open source projects, say how it is licensed.
127
+
128
+ ## Project status
129
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
130
+
@@ -0,0 +1,92 @@
1
+ # agent_api_server
2
+
3
+
4
+
5
+ ## Getting started
6
+
7
+ To make it easy for you to get started with GitLab, here's a list of recommended next steps.
8
+
9
+ Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)!
10
+
11
+ ## Add your files
12
+
13
+ - [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files
14
+ - [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command:
15
+
16
+ ```
17
+ cd existing_repo
18
+ git remote add origin https://gitlab.wise-paas.com/openai/agent_api_server.git
19
+ git branch -M main
20
+ git push -uf origin main
21
+ ```
22
+
23
+ ## Integrate with your tools
24
+
25
+ - [ ] [Set up project integrations](https://gitlab.wise-paas.com/openai/agent_api_server/-/settings/integrations)
26
+
27
+ ## Collaborate with your team
28
+
29
+ - [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/)
30
+ - [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html)
31
+ - [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically)
32
+ - [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/)
33
+ - [ ] [Automatically merge when pipeline succeeds](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html)
34
+
35
+ ## Test and Deploy
36
+
37
+ Use the built-in continuous integration in GitLab.
38
+
39
+ - [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html)
40
+ - [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/)
41
+ - [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html)
42
+ - [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/)
43
+ - [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html)
44
+
45
+ ***
46
+
47
+ # Editing this README
48
+
49
+ When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template.
50
+
51
+ ## Suggestions for a good README
52
+ Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information.
53
+
54
+ ## Name
55
+ Choose a self-explaining name for your project.
56
+
57
+ ## Description
58
+ Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors.
59
+
60
+ ## Badges
61
+ On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge.
62
+
63
+ ## Visuals
64
+ Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method.
65
+
66
+ ## Installation
67
+ Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection.
68
+
69
+ ## Usage
70
+ Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README.
71
+
72
+ ## Support
73
+ Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc.
74
+
75
+ ## Roadmap
76
+ If you have ideas for releases in the future, it is a good idea to list them in the README.
77
+
78
+ ## Contributing
79
+ State if you are open to contributions and what your requirements are for accepting them.
80
+
81
+ For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self.
82
+
83
+ You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser.
84
+
85
+ ## Authors and acknowledgment
86
+ Show your appreciation to those who have contributed to the project.
87
+
88
+ ## License
89
+ For open source projects, say how it is licensed.
90
+
91
+ ## Project status
92
+ If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers.
File without changes
@@ -0,0 +1,25 @@
1
+ import os
2
+ from fastapi import APIRouter
3
+ from agent_api_server.api.v1.schema import api_router as schema_router
4
+ from agent_api_server.api.v1.thread import api_router as thread_router
5
+ from agent_api_server.api.v1.config import api_router as config_router
6
+ from agent_api_server.api.v1.graph import api_router as graph_router
7
+
8
+
9
+
10
+ api_router = APIRouter()
11
+ api_router.include_router(thread_router, prefix="/thread", tags=["thread"])
12
+ api_router.include_router(schema_router, prefix="/schema", tags=["schema"])
13
+ api_router.include_router(config_router, prefix="/config", tags=["config"])
14
+ api_router.include_router(graph_router, prefix="/graph", tags=["graph"])
15
+
16
+
17
+
18
+ @api_router.get("/health")
19
+ async def health_check(
20
+ ):
21
+ """Health check endpoint with connection pool verification"""
22
+ return {
23
+ "message": "Welcome to the LangGraph FastAPI Server!",
24
+ "worker_pid": os.getpid(),
25
+ }
@@ -0,0 +1,57 @@
1
+ import logging
2
+ from fastapi import APIRouter
3
+ from fastapi.responses import JSONResponse
4
+ from agent_api_server.shared.base_model import error_response
5
+ from agent_api_server.shared.util_func import load_graph_config, load_graph
6
+ from langgraph.graph.state import CompiledStateGraph
7
+
8
+ logger = logging.getLogger(__name__)
9
+ api_router = APIRouter()
10
+
11
+ @api_router.get(
12
+ "/",
13
+ responses={
14
+ 200: {
15
+ "description": "Successfully returned config JSON Schema",
16
+ "content": {"application/schema+json": {}}
17
+ },
18
+ 400: {"model": error_response, "description": "Invalid graph instance"},
19
+ 422: {"model": error_response, "description": "Schema validation error"},
20
+ 500: {"model": error_response, "description": "Internal server error"}
21
+ },
22
+ summary="Get JSON Schema for graph_name"
23
+ )
24
+ async def get_config_schema(graph_name: str):
25
+ try:
26
+ graph_cfg = await load_graph_config()
27
+ validated_name, graph_instance, _ = await load_graph(graph_name, graph_cfg, False)
28
+
29
+ if not isinstance(graph_instance, CompiledStateGraph):
30
+ raise error_response(
31
+ status_code=400,
32
+ error_type="invalid_graph",
33
+ message="Graph instance type mismatch",
34
+ graph_name=graph_name,
35
+ actual_type=type(graph_instance).__name__
36
+ )
37
+
38
+ return JSONResponse(
39
+ content=graph_instance.get_context_jsonschema(),
40
+ media_type="application/schema+json",
41
+ )
42
+ except ValueError as ve:
43
+ logger.error(f"Schema validation failed for {graph_name}: {str(ve)}", exc_info=True)
44
+ raise error_response(
45
+ status_code=422,
46
+ error_type="schema_validation",
47
+ message=str(ve),
48
+ graph_name=graph_name
49
+ )
50
+ except Exception as e:
51
+ logger.critical(f"Unexpected error in {graph_name}: {str(e)}", exc_info=True)
52
+ raise error_response(
53
+ status_code=500,
54
+ error_type="internal_error",
55
+ message=str(e),
56
+ graph_name=graph_name
57
+ )
@@ -0,0 +1,59 @@
1
+ import logging
2
+ from fastapi import APIRouter
3
+ from fastapi.responses import JSONResponse
4
+ from fastapi import HTTPException
5
+ from agent_api_server.shared.base_model import error_response
6
+ from agent_api_server.shared.util_func import get_all_graph_names
7
+
8
+ logger = logging.getLogger(__name__)
9
+ api_router = APIRouter()
10
+
11
+
12
+ @api_router.get(
13
+ "/",
14
+ responses={
15
+ 200: {
16
+ "description": "Successfully returned list of available graphs",
17
+ "content": {
18
+ "application/json": {
19
+ "example": {
20
+ "graphs": ["Test_App", "iot_data_analyse"],
21
+ "count": 2
22
+ }
23
+ }
24
+ }
25
+ },
26
+ 500: {"model": error_response, "description": "Internal server error"}
27
+ },
28
+ summary="Get all available graph names",
29
+ response_description="List of available graph names"
30
+ )
31
+ async def get_available_graphs():
32
+ """
33
+ Get all available graph names defined in the configuration file.
34
+
35
+ Returns:
36
+ JSON response containing:
37
+ - graphs: List of available graph names
38
+ - count: Number of available graphs
39
+ """
40
+ try:
41
+ graph_names = await get_all_graph_names()
42
+ return JSONResponse(
43
+ content={
44
+ "graphs": graph_names,
45
+ "count": len(graph_names)
46
+ },
47
+ status_code=200
48
+ )
49
+ except HTTPException as e:
50
+ raise e
51
+ except Exception as e:
52
+ logger.error(f"Failed to get graph names: {str(e)}")
53
+ raise HTTPException(
54
+ status_code=500,
55
+ detail={
56
+ "error": "internal_server_error",
57
+ "message": "Failed to retrieve graph names"
58
+ }
59
+ )
@@ -0,0 +1,57 @@
1
+ import logging
2
+ from fastapi import APIRouter
3
+ from fastapi.responses import JSONResponse
4
+ from agent_api_server.shared.base_model import error_response
5
+ from agent_api_server.shared.util_func import load_graph_config, load_graph
6
+ from langgraph.graph.state import CompiledStateGraph
7
+
8
+ logger = logging.getLogger(__name__)
9
+ api_router = APIRouter()
10
+
11
+ @api_router.get(
12
+ "/",
13
+ responses={
14
+ 200: {
15
+ "description": "Successfully returned JSON Schema",
16
+ "content": {"application/schema+json": {}}
17
+ },
18
+ 400: {"model": error_response, "description": "Invalid graph instance"},
19
+ 422: {"model": error_response, "description": "Schema validation error"},
20
+ 500: {"model": error_response, "description": "Internal server error"}
21
+ },
22
+ summary="Get JSON Schema for graph_name"
23
+ )
24
+ async def get_graph_schema(graph_name: str):
25
+ try:
26
+ graph_cfg = await load_graph_config()
27
+ validated_name, graph_instance, _ = await load_graph(graph_name, graph_cfg, False)
28
+
29
+ if not isinstance(graph_instance, CompiledStateGraph):
30
+ raise error_response(
31
+ status_code=400,
32
+ error_type="invalid_graph",
33
+ message="Graph instance type mismatch",
34
+ graph_name=graph_name,
35
+ actual_type=type(graph_instance).__name__
36
+ )
37
+
38
+ return JSONResponse(
39
+ content=graph_instance.get_input_jsonschema(),
40
+ media_type="application/schema+json",
41
+ )
42
+ except ValueError as ve:
43
+ logger.error(f"Schema validation failed for {graph_name}: {str(ve)}", exc_info=True)
44
+ raise error_response(
45
+ status_code=422,
46
+ error_type="schema_validation",
47
+ message=str(ve),
48
+ graph_name=graph_name
49
+ )
50
+ except Exception as e:
51
+ logger.critical(f"Unexpected error in {graph_name}: {str(e)}", exc_info=True)
52
+ raise error_response(
53
+ status_code=500,
54
+ error_type="internal_error",
55
+ message=str(e),
56
+ graph_name=graph_name
57
+ )