wip(agent-builder): im not sure sure this is actually a good idea

This commit is contained in:
2025-04-18 14:34:29 +01:00
parent 1b1f957e01
commit 6b0fcf3005
9 changed files with 359 additions and 0 deletions

View File

@ -0,0 +1,17 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"github.com/google/uuid"
)
type Agents struct {
ID uuid.UUID `sql:"primary_key"`
Name string
}

View File

@ -0,0 +1,18 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"github.com/google/uuid"
)
type SystemPrompts struct {
ID uuid.UUID `sql:"primary_key"`
Prompt string
AgentID uuid.UUID
}

View File

@ -0,0 +1,18 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package model
import (
"github.com/google/uuid"
)
type Tools struct {
ID uuid.UUID `sql:"primary_key"`
Tool string
AgentID uuid.UUID
}

View File

@ -0,0 +1,78 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var Agents = newAgentsTable("agents", "agents", "")
type agentsTable struct {
postgres.Table
// Columns
ID postgres.ColumnString
Name postgres.ColumnString
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type AgentsTable struct {
agentsTable
EXCLUDED agentsTable
}
// AS creates new AgentsTable with assigned alias
func (a AgentsTable) AS(alias string) *AgentsTable {
return newAgentsTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new AgentsTable with assigned schema name
func (a AgentsTable) FromSchema(schemaName string) *AgentsTable {
return newAgentsTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new AgentsTable with assigned table prefix
func (a AgentsTable) WithPrefix(prefix string) *AgentsTable {
return newAgentsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new AgentsTable with assigned table suffix
func (a AgentsTable) WithSuffix(suffix string) *AgentsTable {
return newAgentsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newAgentsTable(schemaName, tableName, alias string) *AgentsTable {
return &AgentsTable{
agentsTable: newAgentsTableImpl(schemaName, tableName, alias),
EXCLUDED: newAgentsTableImpl("", "excluded", ""),
}
}
func newAgentsTableImpl(schemaName, tableName, alias string) agentsTable {
var (
IDColumn = postgres.StringColumn("id")
NameColumn = postgres.StringColumn("name")
allColumns = postgres.ColumnList{IDColumn, NameColumn}
mutableColumns = postgres.ColumnList{NameColumn}
)
return agentsTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
Name: NameColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@ -0,0 +1,81 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var SystemPrompts = newSystemPromptsTable("agents", "system_prompts", "")
type systemPromptsTable struct {
postgres.Table
// Columns
ID postgres.ColumnString
Prompt postgres.ColumnString
AgentID postgres.ColumnString
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type SystemPromptsTable struct {
systemPromptsTable
EXCLUDED systemPromptsTable
}
// AS creates new SystemPromptsTable with assigned alias
func (a SystemPromptsTable) AS(alias string) *SystemPromptsTable {
return newSystemPromptsTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new SystemPromptsTable with assigned schema name
func (a SystemPromptsTable) FromSchema(schemaName string) *SystemPromptsTable {
return newSystemPromptsTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new SystemPromptsTable with assigned table prefix
func (a SystemPromptsTable) WithPrefix(prefix string) *SystemPromptsTable {
return newSystemPromptsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new SystemPromptsTable with assigned table suffix
func (a SystemPromptsTable) WithSuffix(suffix string) *SystemPromptsTable {
return newSystemPromptsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newSystemPromptsTable(schemaName, tableName, alias string) *SystemPromptsTable {
return &SystemPromptsTable{
systemPromptsTable: newSystemPromptsTableImpl(schemaName, tableName, alias),
EXCLUDED: newSystemPromptsTableImpl("", "excluded", ""),
}
}
func newSystemPromptsTableImpl(schemaName, tableName, alias string) systemPromptsTable {
var (
IDColumn = postgres.StringColumn("id")
PromptColumn = postgres.StringColumn("prompt")
AgentIDColumn = postgres.StringColumn("agent_id")
allColumns = postgres.ColumnList{IDColumn, PromptColumn, AgentIDColumn}
mutableColumns = postgres.ColumnList{PromptColumn, AgentIDColumn}
)
return systemPromptsTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
Prompt: PromptColumn,
AgentID: AgentIDColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

View File

@ -0,0 +1,16 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
// UseSchema sets a new schema name for all generated table SQL builder types. It is recommended to invoke
// this method only once at the beginning of the program.
func UseSchema(schema string) {
Agents = Agents.FromSchema(schema)
SystemPrompts = SystemPrompts.FromSchema(schema)
Tools = Tools.FromSchema(schema)
}

View File

@ -0,0 +1,81 @@
//
// Code generated by go-jet DO NOT EDIT.
//
// WARNING: Changes to this file may cause incorrect behavior
// and will be lost if the code is regenerated
//
package table
import (
"github.com/go-jet/jet/v2/postgres"
)
var Tools = newToolsTable("agents", "tools", "")
type toolsTable struct {
postgres.Table
// Columns
ID postgres.ColumnString
Tool postgres.ColumnString
AgentID postgres.ColumnString
AllColumns postgres.ColumnList
MutableColumns postgres.ColumnList
}
type ToolsTable struct {
toolsTable
EXCLUDED toolsTable
}
// AS creates new ToolsTable with assigned alias
func (a ToolsTable) AS(alias string) *ToolsTable {
return newToolsTable(a.SchemaName(), a.TableName(), alias)
}
// Schema creates new ToolsTable with assigned schema name
func (a ToolsTable) FromSchema(schemaName string) *ToolsTable {
return newToolsTable(schemaName, a.TableName(), a.Alias())
}
// WithPrefix creates new ToolsTable with assigned table prefix
func (a ToolsTable) WithPrefix(prefix string) *ToolsTable {
return newToolsTable(a.SchemaName(), prefix+a.TableName(), a.TableName())
}
// WithSuffix creates new ToolsTable with assigned table suffix
func (a ToolsTable) WithSuffix(suffix string) *ToolsTable {
return newToolsTable(a.SchemaName(), a.TableName()+suffix, a.TableName())
}
func newToolsTable(schemaName, tableName, alias string) *ToolsTable {
return &ToolsTable{
toolsTable: newToolsTableImpl(schemaName, tableName, alias),
EXCLUDED: newToolsTableImpl("", "excluded", ""),
}
}
func newToolsTableImpl(schemaName, tableName, alias string) toolsTable {
var (
IDColumn = postgres.StringColumn("id")
ToolColumn = postgres.StringColumn("tool")
AgentIDColumn = postgres.StringColumn("agent_id")
allColumns = postgres.ColumnList{IDColumn, ToolColumn, AgentIDColumn}
mutableColumns = postgres.ColumnList{ToolColumn, AgentIDColumn}
)
return toolsTable{
Table: postgres.NewTable(schemaName, tableName, alias, allColumns...),
//Columns
ID: IDColumn,
Tool: ToolColumn,
AgentID: AgentIDColumn,
AllColumns: allColumns,
MutableColumns: mutableColumns,
}
}

23
backend/builder/agents.go Normal file
View File

@ -0,0 +1,23 @@
package builder
import (
"context"
"database/sql"
"screenmark/screenmark/.gen/haystack/agents/model"
. "screenmark/screenmark/.gen/haystack/agents/table"
. "github.com/go-jet/jet/v2/postgres"
"github.com/google/uuid"
)
type AgentModel struct {
dbPool *sql.DB
}
func (m AgentModel) SaveTool(ctx context.Context, agentId uuid.UUID, tool string) (model.Tools, error) {
insertToolStmt := Tools.
INSERT(Tools.Tool).
VALUES(Json(tool))
}

View File

@ -1,6 +1,10 @@
DROP SCHEMA IF EXISTS haystack CASCADE; DROP SCHEMA IF EXISTS haystack CASCADE;
DROP SCHEMA IF EXISTS agents CASCADE;
CREATE SCHEMA haystack; CREATE SCHEMA haystack;
CREATE SCHEMA agents;
/** -----| Haystack |----- **/
/* -----| Enums |----- */ /* -----| Enums |----- */
@ -181,6 +185,29 @@ ON haystack.user_images_to_process
FOR EACH ROW FOR EACH ROW
EXECUTE PROCEDURE notify_new_processing_image_status(); EXECUTE PROCEDURE notify_new_processing_image_status();
/** -----| Agents |----- **/
/* -----| Schema tables |----- */
CREATE TABLE agents.agents (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
name TEXT NOT NULL
);
CREATE TABLE agents.system_prompts (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
prompt TEXT NOT NULL,
agent_id UUID NOT NULL REFERENCES agents.agents (id)
);
CREATE TABLE agents.tools (
id uuid PRIMARY KEY DEFAULT gen_random_uuid(),
tool JSONB NOT NULL,
agent_id UUID NOT NULL REFERENCES agents.agents (id)
);
/* -----| Test Data |----- */ /* -----| Test Data |----- */
-- Insert a user -- Insert a user