Skip to content

Commit 750e605

Browse files
committed
feat: create example agent using LangGraph (#4)
Signed-off-by: Richard Gebhardt <[email protected]>
1 parent e425f86 commit 750e605

File tree

19 files changed

+2721
-0
lines changed

19 files changed

+2721
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
**/.env
22
**/.venv
3+
**/.langgraph_api/

agent/.python-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.13

agent/README.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Agent
2+
3+
## Getting started
4+
5+
### Start Ollama and pull model
6+
```bash
7+
brew services start ollama
8+
ollama pull gpt-oss
9+
```
10+
11+
### Install MCP servers
12+
13+
### Authenticate
14+
```bash
15+
oci session authenticate --profile-name <profile name> --region <region name: us-sanjose-1>
16+
```
17+
18+
19+
### Start LangGraph API server
20+
```bash
21+
cd agent/app
22+
uv run langgraph dev --no-browser --allow-blocking
23+
```
24+
25+
### Interact with the server using the client or API endpoint
26+
Client:
27+
```bash
28+
cd ..
29+
uv run client.py
30+
```
31+
32+
cURL
33+
payload.json
34+
```json
35+
{
36+
"assistant_id": "agent",
37+
"input": {
38+
"messages": [
39+
{
40+
"role": "human",
41+
"content": "What is LangGraph?"
42+
}
43+
]
44+
},
45+
"context": {
46+
"model": "ollama:gpt-oss",
47+
"base_url": "http://localhost:11434"
48+
},
49+
"stream_mode": "messages-tuple"
50+
}
51+
```
52+
53+
```bash
54+
curl -s --request POST \
55+
--url "http://localhost:2024/runs/stream" \
56+
--header 'Content-Type: application/json' \
57+
--data @payload.json
58+
```

agent/app/.gitignore

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
uv.lock
6+
7+
# C extensions
8+
*.so
9+
10+
# Distribution / packaging
11+
.Python
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
share/python-wheels/
25+
*.egg-info/
26+
.installed.cfg
27+
*.egg
28+
MANIFEST
29+
30+
# PyInstaller
31+
# Usually these files are written by a python script from a template
32+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
33+
*.manifest
34+
*.spec
35+
36+
# Installer logs
37+
pip-log.txt
38+
pip-delete-this-directory.txt
39+
40+
# Unit test / coverage reports
41+
htmlcov/
42+
.tox/
43+
.nox/
44+
.coverage
45+
.coverage.*
46+
.cache
47+
nosetests.xml
48+
coverage.xml
49+
*.cover
50+
*.py,cover
51+
.hypothesis/
52+
.pytest_cache/
53+
cover/
54+
55+
# Translations
56+
*.mo
57+
*.pot
58+
59+
# Django stuff:
60+
*.log
61+
local_settings.py
62+
db.sqlite3
63+
db.sqlite3-journal
64+
65+
# Flask stuff:
66+
instance/
67+
.webassets-cache
68+
69+
# Scrapy stuff:
70+
.scrapy
71+
72+
# Sphinx documentation
73+
docs/_build/
74+
75+
# PyBuilder
76+
.pybuilder/
77+
target/
78+
79+
# Jupyter Notebook
80+
.ipynb_checkpoints
81+
82+
# IPython
83+
profile_default/
84+
ipython_config.py
85+
86+
# pyenv
87+
# For a library or package, you might want to ignore these files since the code is
88+
# intended to run in multiple environments; otherwise, check them in:
89+
# .python-version
90+
91+
# pipenv
92+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
93+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
94+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
95+
# install all needed dependencies.
96+
#Pipfile.lock
97+
98+
# poetry
99+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
100+
# This is especially recommended for binary packages to ensure reproducibility, and is more
101+
# commonly ignored for libraries.
102+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
103+
#poetry.lock
104+
105+
# pdm
106+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
107+
#pdm.lock
108+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
109+
# in version control.
110+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
111+
.pdm.toml
112+
.pdm-python
113+
.pdm-build/
114+
115+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
116+
__pypackages__/
117+
118+
# Celery stuff
119+
celerybeat-schedule
120+
celerybeat.pid
121+
122+
# SageMath parsed files
123+
*.sage.py
124+
125+
# Environments
126+
.env
127+
.venv
128+
env/
129+
venv/
130+
ENV/
131+
env.bak/
132+
venv.bak/
133+
134+
# Spyder project settings
135+
.spyderproject
136+
.spyproject
137+
138+
# Rope project settings
139+
.ropeproject
140+
141+
# mkdocs documentation
142+
/site
143+
144+
# mypy
145+
.mypy_cache/
146+
.dmypy.json
147+
dmypy.json
148+
149+
# Pyre type checker
150+
.pyre/
151+
152+
# pytype static type analyzer
153+
.pytype/
154+
155+
# Cython debug symbols
156+
cython_debug/
157+
158+
# PyCharm
159+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
160+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
161+
# and can be added to the global gitignore or merged into this file. For a more nuclear
162+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
163+
#.idea/
164+
165+
.langgraph_api

agent/app/LICENSE

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
The Universal Permissive License (UPL), Version 1.0
2+
3+
Subject to the condition set forth below, permission is hereby granted to any
4+
person obtaining a copy of this software, associated documentation and/or data
5+
(collectively the "Software"), free of charge and under any and all copyright
6+
rights in the Software, and any and all patent rights owned or freely
7+
licensable by each licensor hereunder covering either (i) the unmodified
8+
Software as contributed to or provided by such licensor, or (ii) the Larger
9+
Works (as defined below), to deal in both
10+
11+
(a) the Software, and
12+
(b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
13+
one is included with the Software (each a "Larger Work" to which the Software
14+
is contributed by such licensors),
15+
16+
without restriction, including without limitation the rights to copy, create
17+
derivative works of, display, perform, and distribute the Software and make,
18+
use, sell, offer for sale, import, export, have made, and have sold the
19+
Software and the Larger Work(s), and to sublicense the foregoing rights on
20+
either these or other terms.
21+
22+
This license is subject to the following condition:
23+
The above copyright notice and either this complete permission notice or at
24+
a minimum a reference to the UPL must be included in all copies or
25+
substantial portions of the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33+
SOFTWARE.

agent/app/langgraph.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"$schema": "https://langgra.ph/schema.json",
3+
"dependencies": ["."],
4+
"graphs": {
5+
"agent": "./src/react_agent/graph.py:graph"
6+
},
7+
"env": ".env"
8+
}

agent/app/mcp.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"mcpServers": {
3+
"oracle-oci-api-mcp-server": {
4+
"command": "uvx",
5+
"args": [
6+
"oracle.oci-api-mcp-server"
7+
],
8+
"transport": "stdio"
9+
}
10+
}
11+
}

agent/app/pyproject.toml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[project]
2+
name = "react-agent"
3+
version = "0.0.1"
4+
description = "Example agent"
5+
license = "UPL-1.0"
6+
requires-python = ">=3.11,<4.0"
7+
dependencies = [
8+
"langgraph>=0.6.6,<0.7.0",
9+
"langchain-openai>=0.1.22",
10+
"langchain-anthropic>=0.1.23",
11+
"langchain>=0.2.14",
12+
"langchain-fireworks>=0.1.7",
13+
"python-dotenv>=1.0.1",
14+
"langchain-tavily>=0.1",
15+
"langchain-ollama>=0.3.10",
16+
"langchain-mcp-adapters>=0.1.11",
17+
]
18+
19+
[project.optional-dependencies]
20+
dev = ["mypy>=1.11.1", "ruff>=0.6.1"]
21+
22+
[dependency-groups]
23+
dev = [
24+
"langgraph-cli[inmem]>=0.1.71",
25+
"pytest>=8.3.5",
26+
]
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
"""React Agent.
2+
3+
This module defines a custom reasoning and action agent graph.
4+
It invokes tools in a simple loop.
5+
"""
6+
7+
from react_agent.graph import graph
8+
9+
__all__ = ["graph"]
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
"""Define the configurable parameters for the agent."""
2+
3+
from __future__ import annotations
4+
5+
import os
6+
from dataclasses import dataclass, field, fields
7+
from typing import Annotated, Dict
8+
9+
from . import prompts
10+
11+
12+
@dataclass(kw_only=True)
13+
class Context:
14+
"""The context for the agent."""
15+
16+
system_prompt: str = field(
17+
default=prompts.SYSTEM_PROMPT,
18+
metadata={
19+
"description": "The system prompt to use for the agent's interactions. "
20+
"This prompt sets the context and behavior for the agent."
21+
},
22+
)
23+
24+
model: Annotated[str, {"__template_metadata__": {"kind": "llm"}}] = field(
25+
default="anthropic/claude-3-5-sonnet-20240620",
26+
metadata={
27+
"description": "The name of the language model to use for the agent's main interactions. "
28+
"Should be in the form: provider/model-name."
29+
},
30+
)
31+
32+
model_args: Dict[str, str] = field(default_factory=dict)
33+
34+
base_url: str = field(
35+
default="http://localhost:11434",
36+
metadata={"description": "URL to a modelserver, like Ollama"},
37+
)
38+
39+
max_search_results: int = field(
40+
default=10,
41+
metadata={
42+
"description": "The maximum number of search results to return for each search query."
43+
},
44+
)
45+
46+
def __post_init__(self) -> None:
47+
"""Fetch env vars for attributes that were not passed as args."""
48+
for f in fields(self):
49+
if not f.init:
50+
continue
51+
52+
if getattr(self, f.name) == f.default:
53+
setattr(self, f.name, os.environ.get(f.name.upper(), f.default))

0 commit comments

Comments
 (0)