DROP TABLE IF EXISTS agent_definition;

CREATE TABLE agent_definition (
    id BIGSERIAL PRIMARY KEY,
    agent_code VARCHAR(100) NOT NULL,
    agent_name VARCHAR(200) NOT NULL,
    system_prompt TEXT,
    store_id BIGINT NOT NULL,
    status VARCHAR(50) NOT NULL DEFAULT 'ENABLED',
    version INTEGER NOT NULL DEFAULT 1,
    create_time TIMESTAMP,
    update_time TIMESTAMP,
    remark VARCHAR(500) DEFAULT '',
    create_by VARCHAR(64),
    update_by VARCHAR(64),
    CONSTRAINT uk_agent_definition_code UNIQUE (agent_code),
    CONSTRAINT fk_agent_definition_store_id FOREIGN KEY (store_id) REFERENCES rag_store (id)
);

CREATE INDEX idx_agent_definition_store_id ON agent_definition (store_id);
CREATE INDEX idx_agent_definition_status ON agent_definition (status);

COMMENT ON TABLE agent_definition IS 'Agent定义表';
COMMENT ON COLUMN agent_definition.id IS 'ID';
COMMENT ON COLUMN agent_definition.agent_code IS 'Agent编码';
COMMENT ON COLUMN agent_definition.agent_name IS 'Agent名称';
COMMENT ON COLUMN agent_definition.system_prompt IS '系统提示词';
COMMENT ON COLUMN agent_definition.store_id IS '绑定知识库ID';
COMMENT ON COLUMN agent_definition.status IS '状态';
COMMENT ON COLUMN agent_definition.version IS '版本';
COMMENT ON COLUMN agent_definition.create_time IS '创建时间';
COMMENT ON COLUMN agent_definition.update_time IS '更新时间';
COMMENT ON COLUMN agent_definition.remark IS '备注';
COMMENT ON COLUMN agent_definition.create_by IS '创建者';
COMMENT ON COLUMN agent_definition.update_by IS '更新者';
