Skip to content

Commit a64f343

Browse files
authored
Merge pull request #15 from agentuity/openAiAgentsSdkExamples
Add OpenAI framework examples with deterministicStory, translation, a…
2 parents a36382f + 5be2f81 commit a64f343

File tree

17 files changed

+2242
-0
lines changed

17 files changed

+2242
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
description: Guidelines for writing Agentuity AI Agents in Python
3+
globs: "agents/**/*.py"
4+
alwaysApply: true
5+
---
6+
7+
# AI Agent File
8+
9+
- Prefer using the `agentuity agent create` command to create a new Agent
10+
- Prefer importing types from the `agentuity` package
11+
- The file should define an async function named `run`
12+
- All code should follow Python best practices and type hints
13+
- Use the provided logger from the `AgentContext` interface such as `context.logger.info("my message: %s", "hello")`
14+
15+
---
16+
description: Guidelines for writing Agentuity AI Agents in Python
17+
globs: "agents/**/*.py"
18+
alwaysApply: true
19+
---
20+
21+
22+
## Example Agent File
23+
24+
```python
25+
from agentuity import AgentRequest, AgentResponse, AgentContext
26+
27+
async def run(request: AgentRequest, response: AgentResponse, context: AgentContext):
28+
return response.json({"hello": "world"})
29+
```
30+
31+
### AgentRequest
32+
33+
The AgentRequest class provides a set of helper methods and properties which can be used for working with data that has been passed to the Agent.
34+
35+
### AgentResponse
36+
37+
The AgentResponse class provides a set of helper methods for responding with different data formats from the Agent.
38+
39+
### AgentContext
40+
41+
The AgentContext has information specific to the incoming Agent request and a set of helper methods for accessing services like KeyValue storage and Vector storage.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
description: Guidelines for the Agentuity AI Configuration file
3+
globs: "agentuity.yaml"
4+
alwaysApply: true
5+
---
6+
7+
# Agentuity Configuration File
8+
9+
This file is used by Agentuity to configure the AI Agent project. You should NOT suggest edits to this file.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
description: Agentuity Python SDK API Reference
3+
globs: "agents/**/*.py"
4+
---
5+
6+
# Agentuity Python SDK
7+
8+
The Agentuity Python SDK provides a powerful framework for building AI agents in Python. This cursor rules file helps you navigate the SDK's core interfaces and methods.
9+
10+
## Core Interfaces
11+
12+
### Agent Handler
13+
14+
The main handler function for an agent:
15+
16+
```python
17+
async def run(
18+
request: AgentRequest,
19+
response: AgentResponse,
20+
context: AgentContext
21+
) -> Any:
22+
# Agent implementation
23+
pass
24+
```
25+
26+
### AgentRequest
27+
28+
The `AgentRequest` class provides methods for accessing request data:
29+
30+
- `request.trigger`: Gets the trigger type of the request
31+
- `request.metadata`: Gets metadata associated with the request
32+
- `request.get(key, default)`: Gets a value from the metadata
33+
- `request.data.contentType`: Gets the content type of the request payload
34+
- `request.data.json`: Gets the payload as a JSON object
35+
- `request.data.text`: Gets the payload as a string
36+
- `request.data.binary`: Gets the payload as bytes
37+
38+
### AgentResponse
39+
40+
The `AgentResponse` class provides methods for creating responses:
41+
42+
- `response.json(data, metadata)`: Creates a JSON response
43+
- `response.text(data, metadata)`: Creates a text response
44+
- `response.binary(data, content_type, metadata)`: Creates a binary response
45+
- `response.html(data, metadata)`: Creates an HTML response
46+
- `response.empty(metadata)`: Creates an empty response
47+
- `response.handoff(params, args, metadata)`: Redirects to another agent
48+
- Media-specific methods: `pdf()`, `png()`, `jpeg()`, `gif()`, `mp3()`, `mp4()`, etc.
49+
50+
### AgentContext
51+
52+
The `AgentContext` class provides access to various capabilities:
53+
54+
- `context.logger`: Logging functionality
55+
- `context.kv`: Key-Value storage
56+
- `context.vector`: Vector storage
57+
- `context.get_agent(agent_id_or_name)`: Gets a handle to a remote agent
58+
- `context.tracer`: OpenTelemetry tracing
59+
- Environment properties: `sdkVersion`, `devmode`, `orgId`, `projectId`, etc.
60+
61+
## Storage APIs
62+
63+
### Key-Value Storage
64+
65+
Access through `context.kv`:
66+
67+
- `await context.kv.get(name, key)`: Retrieves a value
68+
- `await context.kv.set(name, key, value, params)`: Stores a value with optional params
69+
- `await context.kv.delete(name, key)`: Deletes a value
70+
71+
### Vector Storage
72+
73+
Access through `context.vector`:
74+
75+
- `await context.vector.upsert(name, *documents)`: Inserts or updates vectors
76+
- `await context.vector.search(name, params)`: Searches for vectors
77+
- `await context.vector.delete(name, *ids)`: Deletes vectors
78+
79+
## Logging
80+
81+
Access through `context.logger`:
82+
83+
- `context.logger.debug(message, *args, **kwargs)`: Logs a debug message
84+
- `context.logger.info(message, *args, **kwargs)`: Logs an informational message
85+
- `context.logger.warn(message, *args, **kwargs)`: Logs a warning message
86+
- `context.logger.error(message, *args, **kwargs)`: Logs an error message
87+
- `context.logger.child(**kwargs)`: Creates a child logger with additional context
88+
89+
## Best Practices
90+
91+
- Use type hints for better IDE support
92+
- Import types from `agentuity`
93+
- Use structured error handling with try/except blocks
94+
- Leverage the provided logger for consistent logging
95+
- Use the storage APIs for persisting data
96+
- Consider agent communication for complex workflows
97+
98+
For complete documentation, visit: https://agentuity.dev/SDKs/python/api-reference
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# EditorConfig is awesome: https://EditorConfig.org
2+
3+
# top-most EditorConfig file
4+
root = true
5+
6+
[*]
7+
indent_style = tab
8+
indent_size = 2
9+
end_of_line = lf
10+
charset = utf-8
11+
trim_trailing_whitespace = false
12+
insert_final_newline = false
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
build/
12+
develop-eggs/
13+
dist/
14+
downloads/
15+
eggs/
16+
.eggs/
17+
lib/
18+
lib64/
19+
parts/
20+
sdist/
21+
var/
22+
wheels/
23+
share/python-wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
MANIFEST
28+
29+
# PyInstaller
30+
# Usually these files are written by a python script from a template
31+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32+
*.manifest
33+
*.spec
34+
35+
# Installer logs
36+
pip-log.txt
37+
pip-delete-this-directory.txt
38+
39+
# Unit test / coverage reports
40+
htmlcov/
41+
.tox/
42+
.nox/
43+
.coverage
44+
.coverage.*
45+
.cache
46+
nosetests.xml
47+
coverage.xml
48+
*.cover
49+
*.py,cover
50+
.hypothesis/
51+
.pytest_cache/
52+
cover/
53+
54+
# Translations
55+
*.mo
56+
*.pot
57+
58+
# Django stuff:
59+
*.log
60+
local_settings.py
61+
db.sqlite3
62+
db.sqlite3-journal
63+
64+
# Flask stuff:
65+
instance/
66+
.webassets-cache
67+
68+
# Scrapy stuff:
69+
.scrapy
70+
71+
# Sphinx documentation
72+
docs/_build/
73+
74+
# PyBuilder
75+
.pybuilder/
76+
target/
77+
78+
# Jupyter Notebook
79+
.ipynb_checkpoints
80+
81+
# IPython
82+
profile_default/
83+
ipython_config.py
84+
85+
# pyenv
86+
# For a library or package, you might want to ignore these files since the code is
87+
# intended to run in multiple environments; otherwise, check them in:
88+
# .python-version
89+
90+
# pipenv
91+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94+
# install all needed dependencies.
95+
#Pipfile.lock
96+
97+
# UV
98+
# Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99+
# This is especially recommended for binary packages to ensure reproducibility, and is more
100+
# commonly ignored for libraries.
101+
#uv.lock
102+
103+
# poetry
104+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105+
# This is especially recommended for binary packages to ensure reproducibility, and is more
106+
# commonly ignored for libraries.
107+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108+
#poetry.lock
109+
110+
# pdm
111+
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
112+
#pdm.lock
113+
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
114+
# in version control.
115+
# https://pdm.fming.dev/latest/usage/project/#working-with-version-control
116+
.pdm.toml
117+
.pdm-python
118+
.pdm-build/
119+
120+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
121+
__pypackages__/
122+
123+
# Celery stuff
124+
celerybeat-schedule
125+
celerybeat.pid
126+
127+
# SageMath parsed files
128+
*.sage.py
129+
130+
# Environments
131+
.env
132+
.env.development
133+
.env.production
134+
.venv
135+
env/
136+
venv/
137+
ENV/
138+
env.bak/
139+
venv.bak/
140+
141+
# Spyder project settings
142+
.spyderproject
143+
.spyproject
144+
145+
# Rope project settings
146+
.ropeproject
147+
148+
# mkdocs documentation
149+
/site
150+
151+
# mypy
152+
.mypy_cache/
153+
.dmypy.json
154+
dmypy.json
155+
156+
# Pyre type checker
157+
.pyre/
158+
159+
# pytype static type analyzer
160+
.pytype/
161+
162+
# Cython debug symbols
163+
cython_debug/
164+
165+
# PyCharm
166+
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
167+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
168+
# and can be added to the global gitignore or merged into this file. For a more nuclear
169+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
170+
#.idea/
171+
172+
# Ruff stuff:
173+
.ruff_cache/
174+
175+
# PyPI configuration file
176+
.pypirc
177+
178+
# Agentuity
179+
.agentuity
180+
.agentuity-crash-*.json
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
3.11

0 commit comments

Comments
 (0)