You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/lobsterx/README.md
+89-4Lines changed: 89 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,6 +41,8 @@ You then need to set three required env variables:
41
41
-`TELEGRAM_BOT_TOKEN`: token for the Telegram bot
42
42
-`LLAMA_CLOUD_API_KEY`: API key for LlamaCloud
43
43
44
+
If you wish to setup LobsterX as an API server, you will need to set an API key that only you can use to interact with it, set in the environment as `LOBSTERX_SERVER_KEY`. The key has to be at least 32 charachters long and contain only lowercase and uppercase alphanumeric characters, `-` and `_`.
45
+
44
46
You can use the setup wizard to configure LobsterX interactively on the terminal:
45
47
46
48
```bash
@@ -54,7 +56,8 @@ lobsterx setup --provider google \
54
56
--model gemini-3-flash-preview \
55
57
--api-key $GOOGLE_API_KEY \
56
58
--llama-cloud-key $LLAMA_CLOUD_API_KEY \
57
-
--telegram-token $TELEGRAM_BOT_TOKEN
59
+
--telegram-token $TELEGRAM_BOT_TOKEN \
60
+
--server-key $SERVER_KEY
58
61
```
59
62
60
63
This will create a `.env` file with the necessary variables, which will be loaded by LobsterX at runtime (make sure not to share it with anyone).
@@ -63,7 +66,9 @@ If you wish to further customize the instructions that LobsterX has access to, y
63
66
64
67
## Run
65
68
66
-
Run LobsterX as a CLI app:
69
+
### As a Telegram Bot
70
+
71
+
Run LobsterX as a Telegram Bot:
67
72
68
73
```bash
69
74
lobsterx run
@@ -88,15 +93,85 @@ docker run ghcr.io/astrabert/lobsterx:main \
88
93
--env="TELEGRAM_BOT_TOKEN=tok-xxx"
89
94
```
90
95
91
-
## Use as a Telegram Bot
92
-
93
96
When on Telegram, you can perform two actions:
94
97
95
98
- Sending PDF files, which will be downloaded by the bot
96
99
- Sending text messages, which will work as prompts for the bot to start a new task
97
100
98
101
> _With `/start` command, you will have a welcome message explaining how to use the bot_
99
102
103
+
### As an API server
104
+
105
+
To run as an API server, you need to specify a series of options that are necessary for authentication, rate limiting and CORS.
106
+
107
+
- For **authentication**, you need to set the `LOBSTERX_SERVER_KEY` within the environment or in a `.env` file in the same working directory as the agent
108
+
- For **CORS**, you can set a list of allowed origins
109
+
- For **rate limiting**, you can set the maximum limits of file uploads, task creations, task polling and task deletion per minute
110
+
111
+
In addition to these, you will also need to provide the host (`0.0.0.0` e.g.), port (`8000` e.g.) and protocol (`http` or `https`) on which the server will run.
112
+
113
+
You can provide all of these details directly from the CLI:
114
+
115
+
```bash
116
+
lobsterx serve \
117
+
--file-downloads-per-minute 300 \
118
+
--create-tasks-per-minute 60 \
119
+
--delete-tasks-per-minute 60 \
120
+
--poll-tasks-per-minute 300 \
121
+
--bind 0.0.0.0 \
122
+
--port 8000 \
123
+
--protocol http \
124
+
--allow https://example.com \
125
+
--allow https://anotherexample.com
126
+
```
127
+
128
+
> All of these options have sensible defaults, but personalization is always recommended
129
+
130
+
Or create a JSON configuration ([as in thie example](config.api.json)) following this specification:
131
+
132
+
```json
133
+
{
134
+
"allow_origins": [],
135
+
"file_downloads_per_minute": 300,
136
+
"create_tasks_per_minute": 60,
137
+
"delete_tasks_per_minute": 60,
138
+
"poll_tasks_per_minute": 300,
139
+
"host": "0.0.0.0",
140
+
"port": 8000,
141
+
"protocol": "http"
142
+
}
143
+
```
144
+
145
+
And provide it to the CLI:
146
+
147
+
```bash
148
+
lobsterx serve --config config.api.json
149
+
```
150
+
151
+
> The configuration approach is recommended, as it can be re-use through different API-related commands.
152
+
153
+
Once you are serving your API through `lobsterx serve`, you can:
154
+
155
+
- Upload files, by sending a POST request to `/files`
156
+
- Create tasks, by sending a POST request to `/task`
157
+
- Get the status of a task, by sending a GET request to `/task/{task_id}`
158
+
- Cancel a task, by sending a DELETE request to `/task/{task_id}`
159
+
160
+
You don't have to do this through raw API calls, the LobsterX CLI provides several commands to perform these operations on your behalf:
161
+
162
+
```bash
163
+
# upload a file
164
+
lobsterx upload-file path/to/file.pdf --config config.api.json # pass the server configuration
165
+
# start a task
166
+
lobsterx create-task "Your prompt" --config config.api.json # this will return a task ID
LobsterX is a generalist AI agent based on three main principles:
@@ -111,6 +186,16 @@ Here is what happens when you send a prompt to LobsterX:
111
186
112
187
Along with the final response, the agent will also send you a report of everything it did during its session as a markdown file (namedd `session-<random-id>-report.md`).
113
188
189
+
### The API server
190
+
191
+
While sharing the core desing principles outlined above, the API server has some more features related to the data flow:
192
+
193
+
- When a POST request to the `/tasks` endpoint (task creation) is made, a new `asyncio.Task` is spawned and stored within a in-memory task manager, using a locked dictionary to associate a task ID with an async Task.
194
+
- When a GET request is sent to `/task/{task_id}`, the task manager provides details on the status of the task (`success`, `failed`, `cancelled`, `pending`). If the task was succesfull, failed or was cancelled, it is removed from the dictionary.
195
+
- When a DELETE request is sent to `/task/{task_id}`, the async Task is cancelled and removed from the dictionary
196
+
197
+
Besides the Task Manager, the API server uses an in-memory rate limiter ([`fastapi-throttle`](https://github.com/AliYmn/fastapi-throttle)) and Starlette CORS and Auth middleawares to provide authentication (through a `Bearer` token provided with an `Authorization` header) and CORS servicres.
198
+
114
199
## License
115
200
116
201
This package is provided under [MIT License](./LICENSE)
0 commit comments