hyperforge 1.0.0.post19__py3-none-any.whl
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.
- hyperforge/__init__.py +16 -0
- hyperforge/agent.py +81 -0
- hyperforge/api/__init__.py +20 -0
- hyperforge/api/app.py +155 -0
- hyperforge/api/authentication.py +271 -0
- hyperforge/api/commands.py +33 -0
- hyperforge/api/internal/__init__.py +4 -0
- hyperforge/api/internal/inspect.py +30 -0
- hyperforge/api/internal/router.py +3 -0
- hyperforge/api/logging.py +18 -0
- hyperforge/api/models.py +129 -0
- hyperforge/api/session.py +197 -0
- hyperforge/api/settings.py +38 -0
- hyperforge/api/utils.py +354 -0
- hyperforge/api/v1/__init__.py +23 -0
- hyperforge/api/v1/agents.py +531 -0
- hyperforge/api/v1/interaction.py +430 -0
- hyperforge/api/v1/mcp_content.py +311 -0
- hyperforge/api/v1/mcp_interaction.py +322 -0
- hyperforge/api/v1/oauth.py +60 -0
- hyperforge/api/v1/prompt.py +129 -0
- hyperforge/api/v1/router.py +3 -0
- hyperforge/api/v1/schema.py +56 -0
- hyperforge/api/v1/session.py +182 -0
- hyperforge/api/v1/utils.py +12 -0
- hyperforge/api/v1/workflows.py +643 -0
- hyperforge/arag.py +28 -0
- hyperforge/broker/__init__.py +52 -0
- hyperforge/broker/local.py +116 -0
- hyperforge/broker/redis.py +161 -0
- hyperforge/configure.py +571 -0
- hyperforge/context/__init__.py +0 -0
- hyperforge/context/agent.py +377 -0
- hyperforge/context/config.py +103 -0
- hyperforge/database.py +3 -0
- hyperforge/db/__init__.py +6 -0
- hyperforge/db/agents.py +1521 -0
- hyperforge/db/encryption.py +91 -0
- hyperforge/db/exceptions.py +26 -0
- hyperforge/db/settings.py +16 -0
- hyperforge/db/workflow_cleanup.py +69 -0
- hyperforge/definition.py +13 -0
- hyperforge/driver.py +31 -0
- hyperforge/dummy.py +28 -0
- hyperforge/engine.py +189 -0
- hyperforge/exceptions.py +14 -0
- hyperforge/feature_flag.py +105 -0
- hyperforge/fixtures.py +602 -0
- hyperforge/interaction.py +116 -0
- hyperforge/llm.py +75 -0
- hyperforge/manager.py +432 -0
- hyperforge/memory/__init__.py +5 -0
- hyperforge/memory/memory.py +974 -0
- hyperforge/minimal_fixtures.py +75 -0
- hyperforge/models.py +336 -0
- hyperforge/nua.py +336 -0
- hyperforge/openapi.py +63 -0
- hyperforge/prompts.py +188 -0
- hyperforge/pubsub.py +90 -0
- hyperforge/py.typed +0 -0
- hyperforge/redis_utils.py +82 -0
- hyperforge/retrieval/__init__.py +0 -0
- hyperforge/retrieval/agent.py +169 -0
- hyperforge/retrieval/config.py +94 -0
- hyperforge/server/__init__.py +5 -0
- hyperforge/server/cache.py +131 -0
- hyperforge/server/run.py +109 -0
- hyperforge/server/sandbox.py +60 -0
- hyperforge/server/session.py +421 -0
- hyperforge/server/settings.py +47 -0
- hyperforge/server/utils.py +57 -0
- hyperforge/server/web.py +31 -0
- hyperforge/settings.py +18 -0
- hyperforge/standalone/__init__.py +5 -0
- hyperforge/standalone/agent.py +189 -0
- hyperforge/standalone/app.py +264 -0
- hyperforge/standalone/config.py +137 -0
- hyperforge/standalone/const.py +1 -0
- hyperforge/standalone/run.py +60 -0
- hyperforge/standalone/settings.py +133 -0
- hyperforge/standalone/ui_router.py +241 -0
- hyperforge/trace.py +42 -0
- hyperforge/utils/__init__.py +112 -0
- hyperforge/utils/http.py +48 -0
- hyperforge/workflows.py +44 -0
- hyperforge-1.0.0.post19.dist-info/METADATA +95 -0
- hyperforge-1.0.0.post19.dist-info/RECORD +90 -0
- hyperforge-1.0.0.post19.dist-info/WHEEL +5 -0
- hyperforge-1.0.0.post19.dist-info/entry_points.txt +8 -0
- hyperforge-1.0.0.post19.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
from fastapi import Header
|
|
2
|
+
from starlette.requests import Request
|
|
3
|
+
|
|
4
|
+
from hyperforge.api.authentication import requires_one
|
|
5
|
+
from hyperforge.api.models import PromptID, StashRoles
|
|
6
|
+
from hyperforge.api.v1.router import router
|
|
7
|
+
from hyperforge.db.agents import AgentManager
|
|
8
|
+
from hyperforge.prompts import PromptConfig
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@router.post(
|
|
12
|
+
"/api/v1/agent/{agent_id}/prompts",
|
|
13
|
+
status_code=200,
|
|
14
|
+
description="Add Prompt to Agent",
|
|
15
|
+
tags=["Prompt Management"],
|
|
16
|
+
)
|
|
17
|
+
@requires_one([StashRoles.OWNER])
|
|
18
|
+
async def add_prompt(
|
|
19
|
+
request: Request,
|
|
20
|
+
agent_id: str,
|
|
21
|
+
item: PromptConfig,
|
|
22
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
23
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
24
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
25
|
+
) -> PromptID:
|
|
26
|
+
agent_manager: AgentManager = request.app.agent_manager
|
|
27
|
+
prompt_id = await agent_manager.add_prompt(
|
|
28
|
+
account=x_stf_account,
|
|
29
|
+
agent_id=agent_id,
|
|
30
|
+
prompt=item,
|
|
31
|
+
)
|
|
32
|
+
return PromptID(id=prompt_id)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
@router.patch(
|
|
36
|
+
"/api/v1/agent/{agent_id}/prompt/{prompt_id}",
|
|
37
|
+
status_code=200,
|
|
38
|
+
description="Update Prompt of Agent",
|
|
39
|
+
tags=["Prompt Management"],
|
|
40
|
+
)
|
|
41
|
+
@requires_one([StashRoles.OWNER])
|
|
42
|
+
async def patch_prompt(
|
|
43
|
+
request: Request,
|
|
44
|
+
agent_id: str,
|
|
45
|
+
prompt_id: str,
|
|
46
|
+
item: PromptConfig,
|
|
47
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
48
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
49
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
50
|
+
):
|
|
51
|
+
agent_manager: AgentManager = request.app.agent_manager
|
|
52
|
+
|
|
53
|
+
await agent_manager.set_prompt(
|
|
54
|
+
account=x_stf_account, agent_id=agent_id, prompt=item, prompt_id=prompt_id
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
@router.delete(
|
|
59
|
+
"/api/v1/agent/{agent_id}/prompt/{prompt_id}",
|
|
60
|
+
status_code=200,
|
|
61
|
+
description="Delete prompt id",
|
|
62
|
+
tags=["Prompt Management"],
|
|
63
|
+
)
|
|
64
|
+
@requires_one([StashRoles.OWNER])
|
|
65
|
+
async def delete_prompt(
|
|
66
|
+
request: Request,
|
|
67
|
+
agent_id: str,
|
|
68
|
+
prompt_id: str,
|
|
69
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
70
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
71
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
72
|
+
):
|
|
73
|
+
agent_manager: AgentManager = request.app.agent_manager
|
|
74
|
+
|
|
75
|
+
return await agent_manager.delete_prompt(
|
|
76
|
+
account=x_stf_account, agent_id=agent_id, prompt_id=prompt_id
|
|
77
|
+
)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
@router.get(
|
|
81
|
+
"/api/v1/agent/{agent_id}/prompts",
|
|
82
|
+
status_code=200,
|
|
83
|
+
description="Get Agent Configuration",
|
|
84
|
+
tags=["Prompt Management"],
|
|
85
|
+
)
|
|
86
|
+
@requires_one([StashRoles.OWNER])
|
|
87
|
+
async def get_prompts(
|
|
88
|
+
request: Request,
|
|
89
|
+
agent_id: str,
|
|
90
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
91
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
92
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
93
|
+
) -> list[PromptConfig]:
|
|
94
|
+
agent_manager: AgentManager = request.app.agent_manager
|
|
95
|
+
|
|
96
|
+
# TODO: This returns PromptConfig while the rest of APIs use PromptConfigs
|
|
97
|
+
# Standardize (into the simpler PromptConfigs?) for consistency
|
|
98
|
+
# Same for the `get_prompt` function
|
|
99
|
+
prompts = await agent_manager.get_prompts(
|
|
100
|
+
account=x_stf_account,
|
|
101
|
+
agent_id=agent_id,
|
|
102
|
+
)
|
|
103
|
+
return prompts
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
@router.get(
|
|
107
|
+
"/api/v1/agent/{agent_id}/prompt/{prompt_id}",
|
|
108
|
+
status_code=200,
|
|
109
|
+
description="Get Agent Configuration",
|
|
110
|
+
tags=["Prompt Management"],
|
|
111
|
+
)
|
|
112
|
+
@requires_one([StashRoles.OWNER])
|
|
113
|
+
async def get_prompt(
|
|
114
|
+
request: Request,
|
|
115
|
+
agent_id: str,
|
|
116
|
+
prompt_id: str,
|
|
117
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
118
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
119
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
120
|
+
) -> PromptConfig:
|
|
121
|
+
agent_manager: AgentManager = request.app.agent_manager
|
|
122
|
+
|
|
123
|
+
# TODO: This returns PromptConfig while the rest of APIs use PromptConfigs
|
|
124
|
+
# Standardize (into the simpler PromptConfigs?) for consistency
|
|
125
|
+
# Same for the `get_prompt` function
|
|
126
|
+
prompt = await agent_manager.get_prompt(
|
|
127
|
+
account=x_stf_account, agent_id=agent_id, prompt_id=prompt_id
|
|
128
|
+
)
|
|
129
|
+
return prompt
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
from fastapi import Header
|
|
2
|
+
from starlette.requests import Request
|
|
3
|
+
|
|
4
|
+
from hyperforge.api.authentication import requires_one
|
|
5
|
+
from hyperforge.api.models import StashRoles
|
|
6
|
+
from hyperforge.api.v1.router import router
|
|
7
|
+
from hyperforge.configure import (
|
|
8
|
+
get_context_agent_schemas,
|
|
9
|
+
get_driver_agent_schemas,
|
|
10
|
+
get_generation_agent_schemas,
|
|
11
|
+
get_postprocess_agent_schemas,
|
|
12
|
+
get_preprocess_agent_schemas,
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@router.get(
|
|
17
|
+
"/api/v1/agent/{agent_id}/schema",
|
|
18
|
+
status_code=200,
|
|
19
|
+
description="Get Agent Schema",
|
|
20
|
+
tags=["Retrieval Agent"],
|
|
21
|
+
include_in_schema=False,
|
|
22
|
+
)
|
|
23
|
+
@requires_one([StashRoles.OWNER])
|
|
24
|
+
async def get_schema(
|
|
25
|
+
request: Request,
|
|
26
|
+
agent_id: str,
|
|
27
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
28
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
29
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
30
|
+
):
|
|
31
|
+
schema = {
|
|
32
|
+
"agents": {
|
|
33
|
+
"context": get_context_agent_schemas(
|
|
34
|
+
running_environment=request.app.settings.running_environment,
|
|
35
|
+
account_id=x_stf_account,
|
|
36
|
+
),
|
|
37
|
+
"preprocess": get_preprocess_agent_schemas(
|
|
38
|
+
running_environment=request.app.settings.running_environment,
|
|
39
|
+
account_id=x_stf_account,
|
|
40
|
+
),
|
|
41
|
+
"generation": get_generation_agent_schemas(
|
|
42
|
+
running_environment=request.app.settings.running_environment,
|
|
43
|
+
account_id=x_stf_account,
|
|
44
|
+
),
|
|
45
|
+
"postprocess": get_postprocess_agent_schemas(
|
|
46
|
+
running_environment=request.app.settings.running_environment,
|
|
47
|
+
account_id=x_stf_account,
|
|
48
|
+
),
|
|
49
|
+
},
|
|
50
|
+
"drivers": get_driver_agent_schemas(
|
|
51
|
+
running_environment=request.app.settings.running_environment,
|
|
52
|
+
account_id=x_stf_account,
|
|
53
|
+
),
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return schema
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
from typing import TYPE_CHECKING
|
|
2
|
+
|
|
3
|
+
from fastapi import Header, HTTPException, Query
|
|
4
|
+
from nucliadb_models import ResourceCreated
|
|
5
|
+
from nucliadb_models.resource import Resource, ResourceList
|
|
6
|
+
from nucliadb_sdk import NucliaDBAsync
|
|
7
|
+
from starlette.requests import Request
|
|
8
|
+
|
|
9
|
+
from hyperforge import logger
|
|
10
|
+
from hyperforge.api.authentication import requires_one
|
|
11
|
+
|
|
12
|
+
if TYPE_CHECKING:
|
|
13
|
+
from hyperforge.api.app import HTTPApplication
|
|
14
|
+
from nucliadb_sdk.v2.exceptions import NotFoundError
|
|
15
|
+
|
|
16
|
+
from hyperforge.api.models import (
|
|
17
|
+
DEFAULT_RESOURCE_LIST_PAGE_SIZE,
|
|
18
|
+
SessionData,
|
|
19
|
+
StashRoles,
|
|
20
|
+
)
|
|
21
|
+
from hyperforge.api.session import (
|
|
22
|
+
create_session_resource,
|
|
23
|
+
delete_session_resource,
|
|
24
|
+
get_session_resource,
|
|
25
|
+
list_session_resources,
|
|
26
|
+
update_session_resource,
|
|
27
|
+
)
|
|
28
|
+
from hyperforge.api.utils import requires_nucliadb_memory
|
|
29
|
+
from hyperforge.api.v1.router import router
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@router.post(
|
|
33
|
+
"/api/v1/agent/{agent_id}/sessions",
|
|
34
|
+
status_code=200,
|
|
35
|
+
description="Create session",
|
|
36
|
+
tags=["Retrieval Agent"],
|
|
37
|
+
)
|
|
38
|
+
@requires_one([StashRoles.OWNER])
|
|
39
|
+
@requires_nucliadb_memory
|
|
40
|
+
async def create_session(
|
|
41
|
+
request: Request,
|
|
42
|
+
item: SessionData,
|
|
43
|
+
agent_id: str,
|
|
44
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
45
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
46
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
47
|
+
) -> ResourceCreated:
|
|
48
|
+
app: HTTPApplication = request.app
|
|
49
|
+
ndb: NucliaDBAsync = app.arag_writer
|
|
50
|
+
|
|
51
|
+
try:
|
|
52
|
+
created = await create_session_resource(
|
|
53
|
+
ndb=ndb,
|
|
54
|
+
agent_id=agent_id,
|
|
55
|
+
slug=item.slug,
|
|
56
|
+
title=item.name,
|
|
57
|
+
summary=item.summary,
|
|
58
|
+
data=item.data,
|
|
59
|
+
format=item.format,
|
|
60
|
+
)
|
|
61
|
+
return created
|
|
62
|
+
except Exception as e:
|
|
63
|
+
logger.exception(f"Error creating session on nucliadb: {e}")
|
|
64
|
+
raise HTTPException(status_code=422, detail="Failed to create session")
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@router.patch(
|
|
68
|
+
"/api/v1/agent/{agent_id}/session/{session}",
|
|
69
|
+
status_code=200,
|
|
70
|
+
description="Create session",
|
|
71
|
+
tags=["Retrieval Agent"],
|
|
72
|
+
)
|
|
73
|
+
@requires_one([StashRoles.OWNER])
|
|
74
|
+
@requires_nucliadb_memory
|
|
75
|
+
async def patch_session(
|
|
76
|
+
request: Request,
|
|
77
|
+
agent_id: str,
|
|
78
|
+
session: str,
|
|
79
|
+
item: SessionData,
|
|
80
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
81
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
82
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
83
|
+
):
|
|
84
|
+
app: HTTPApplication = request.app
|
|
85
|
+
ndb: NucliaDBAsync = app.arag_writer
|
|
86
|
+
try:
|
|
87
|
+
await update_session_resource(
|
|
88
|
+
ndb=ndb,
|
|
89
|
+
agent_id=agent_id,
|
|
90
|
+
session_id=session,
|
|
91
|
+
title=item.name,
|
|
92
|
+
summary=item.summary,
|
|
93
|
+
data=item.data,
|
|
94
|
+
format=item.format,
|
|
95
|
+
)
|
|
96
|
+
except NotFoundError:
|
|
97
|
+
raise HTTPException(status_code=404, detail="Session not found")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@router.delete(
|
|
101
|
+
"/api/v1/agent/{agent_id}/session/{session}",
|
|
102
|
+
status_code=200,
|
|
103
|
+
description="Delete session",
|
|
104
|
+
tags=["Retrieval Agent"],
|
|
105
|
+
)
|
|
106
|
+
@requires_one([StashRoles.OWNER])
|
|
107
|
+
@requires_nucliadb_memory
|
|
108
|
+
async def delete_session(
|
|
109
|
+
request: Request,
|
|
110
|
+
agent_id: str,
|
|
111
|
+
session: str,
|
|
112
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
113
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
114
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
115
|
+
):
|
|
116
|
+
app: HTTPApplication = request.app
|
|
117
|
+
ndb: NucliaDBAsync = app.arag_writer
|
|
118
|
+
try:
|
|
119
|
+
await delete_session_resource(
|
|
120
|
+
ndb=ndb,
|
|
121
|
+
agent_id=agent_id,
|
|
122
|
+
session_id=session,
|
|
123
|
+
)
|
|
124
|
+
except NotFoundError:
|
|
125
|
+
raise HTTPException(status_code=404, detail="Session not found")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
@router.get(
|
|
129
|
+
"/api/v1/agent/{agent_id}/sessions",
|
|
130
|
+
status_code=200,
|
|
131
|
+
description="Create session",
|
|
132
|
+
tags=["Retrieval Agent"],
|
|
133
|
+
)
|
|
134
|
+
@requires_one([StashRoles.OWNER])
|
|
135
|
+
@requires_nucliadb_memory
|
|
136
|
+
async def get_sessions(
|
|
137
|
+
request: Request,
|
|
138
|
+
agent_id: str,
|
|
139
|
+
page: int = Query(0, description="Requested page number (0-based)"),
|
|
140
|
+
size: int = Query(DEFAULT_RESOURCE_LIST_PAGE_SIZE, description="Page size"),
|
|
141
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
142
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
143
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
144
|
+
) -> ResourceList:
|
|
145
|
+
app: HTTPApplication = request.app
|
|
146
|
+
ndb: NucliaDBAsync = app.arag_reader
|
|
147
|
+
|
|
148
|
+
return await list_session_resources(
|
|
149
|
+
ndb=ndb,
|
|
150
|
+
agent_id=agent_id,
|
|
151
|
+
page=page,
|
|
152
|
+
size=size,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@router.get(
|
|
157
|
+
"/api/v1/agent/{agent_id}/session/{session}",
|
|
158
|
+
status_code=200,
|
|
159
|
+
description="Create session",
|
|
160
|
+
tags=["Retrieval Agent"],
|
|
161
|
+
)
|
|
162
|
+
@requires_one([StashRoles.OWNER])
|
|
163
|
+
@requires_nucliadb_memory
|
|
164
|
+
async def get_session(
|
|
165
|
+
request: Request,
|
|
166
|
+
agent_id: str,
|
|
167
|
+
session: str,
|
|
168
|
+
x_stf_user: str = Header(..., include_in_schema=False),
|
|
169
|
+
x_stf_account: str = Header(..., include_in_schema=False),
|
|
170
|
+
x_stf_account_type: str = Header(..., include_in_schema=False),
|
|
171
|
+
) -> Resource:
|
|
172
|
+
app: HTTPApplication = request.app
|
|
173
|
+
ndb: NucliaDBAsync = app.arag_reader
|
|
174
|
+
try:
|
|
175
|
+
return await get_session_resource(
|
|
176
|
+
ndb=ndb,
|
|
177
|
+
agent_id=agent_id,
|
|
178
|
+
session_id=session,
|
|
179
|
+
show=["basic", "values"],
|
|
180
|
+
)
|
|
181
|
+
except NotFoundError:
|
|
182
|
+
raise HTTPException(status_code=404, detail="Session not found")
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
from nucliadb_telemetry.utils import get_telemetry
|
|
2
|
+
from opentelemetry import trace
|
|
3
|
+
|
|
4
|
+
from hyperforge.api import SERVICE_NAME
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def tracer():
|
|
8
|
+
provider = get_telemetry(SERVICE_NAME)
|
|
9
|
+
if provider:
|
|
10
|
+
return provider.get_tracer(__name__)
|
|
11
|
+
else:
|
|
12
|
+
return trace.NoOpTracer()
|