Skip to content

Commit b319504

Browse files
updated the operation for creating an Agent
1 parent 2ad077e commit b319504

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

mindsdb_sdk/agents.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -486,19 +486,26 @@ def add_database(self, name: str, database: str, tables: List[str], description:
486486
self.update(agent.name, agent)
487487

488488
def create(
489-
self,
490-
name: str,
491-
model: Union[Model, dict, str] = None,
492-
provider: str = None,
493-
skills: List[Union[Skill, str]] = None,
494-
params: dict = None,
495-
**kwargs) -> Agent:
489+
self,
490+
name: str,
491+
model_name: Union[Model, str] = None,
492+
provider: str = None,
493+
skills: List[Union[Skill, str]] = None,
494+
data: dict = None,
495+
model: dict = None,
496+
prompt_template: str = None,
497+
params: dict = None,
498+
**kwargs
499+
) -> Agent:
496500
"""
497501
Create new agent and return it
498502
499503
:param name: Name of the agent to be created
500-
:param model: Model to be used by the agent
504+
:param model_name: MindsDB model to be used by the agent
501505
:param skills: List of skills to be used by the agent. Currently only 'sql' is supported.
506+
:param provider: Provider of the model, e.g. 'mindsdb', 'openai', etc.
507+
:param data: Data to be used by the agent. This is usually a dictionary with 'tables' and/or 'knowledge_base' keys.
508+
:param model: Model parameters to be used by the agent. This is usually a dictionary
502509
:param params: Parameters for the agent
503510
504511
:return: created agent object
@@ -519,18 +526,23 @@ def create(
519526
if params is None:
520527
params = {}
521528
params.update(kwargs)
522-
523-
if 'prompt_template' not in params:
524-
params['prompt_template'] = _DEFAULT_LLM_PROMPT
525-
526-
if model is None:
527-
model = _DEFAULT_LLM_MODEL
528-
elif isinstance(model, Model):
529-
model = model.name
529+
530+
if isinstance(model_name, Model):
531+
model_name = model_name.name
530532
provider = 'mindsdb'
531533

532-
data = self.api.create_agent(self.project.name, name, model, provider, skill_names, params)
533-
return Agent.from_json(data, self)
534+
agent = self.api.create_agent(
535+
self.project.name,
536+
name,
537+
model_name,
538+
provider,
539+
skill_names,
540+
data,
541+
model,
542+
prompt_template,
543+
params
544+
)
545+
return Agent.from_json(agent, self)
534546

535547
def update(self, name: str, updated_agent: Agent):
536548
"""

mindsdb_sdk/connectors/rest_api.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,16 +306,30 @@ def agent_completion_stream_v2(self, project: str, name: str, messages: List[dic
306306
yield e
307307

308308
@_try_relogin
309-
def create_agent(self, project: str, name: str, model: str = None, provider: str = None, skills: List[str] = None, params: dict = None):
309+
def create_agent(
310+
self,
311+
project: str,
312+
name: str,
313+
model_name: str = None,
314+
provider: str = None,
315+
skills: List[str] = None,
316+
data: dict = None,
317+
model: dict = None,
318+
prompt_template: str = None,
319+
params: dict = None
320+
):
310321
url = self.url + f'/api/projects/{project}/agents'
311322
r = self.session.post(
312323
url,
313324
json={
314325
'agent': {
315326
'name': name,
316-
'model_name': model,
327+
'model_name': model_name,
317328
'provider': provider,
318329
'skills': skills,
330+
'data': data,
331+
'model': model,
332+
'prompt_template': prompt_template,
319333
'params': params
320334
}
321335
}

0 commit comments

Comments
 (0)