fix: agent strategy (#2141)

This commit is contained in:
Yeuoly 2024-01-23 21:04:46 +08:00 committed by GitHub
parent 23e02d8eb0
commit 21ade71bad
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -419,8 +419,9 @@ class ApplicationManager:
datasets = {'strategy': 'router', 'datasets': []} datasets = {'strategy': 'router', 'datasets': []}
if 'agent_mode' in copy_app_model_config_dict and copy_app_model_config_dict['agent_mode'] \ if 'agent_mode' in copy_app_model_config_dict and copy_app_model_config_dict['agent_mode'] \
and 'enabled' in copy_app_model_config_dict['agent_mode'] and copy_app_model_config_dict['agent_mode'][ and 'enabled' in copy_app_model_config_dict['agent_mode'] \
'enabled']: and copy_app_model_config_dict['agent_mode']['enabled']:
agent_dict = copy_app_model_config_dict.get('agent_mode', {}) agent_dict = copy_app_model_config_dict.get('agent_mode', {})
agent_strategy = agent_dict.get('strategy', 'cot') agent_strategy = agent_dict.get('strategy', 'cot')
@ -465,28 +466,30 @@ class ApplicationManager:
dataset_id = tool_item['id'] dataset_id = tool_item['id']
dataset_ids.append(dataset_id) dataset_ids.append(dataset_id)
agent_prompt = agent_dict.get('prompt', None) or {} if 'strategy' in copy_app_model_config_dict['agent_mode'] and \
# check model mode copy_app_model_config_dict['agent_mode']['strategy'] not in ['react_router', 'router']:
model_mode = copy_app_model_config_dict.get('model', {}).get('mode', 'completion') agent_prompt = agent_dict.get('prompt', None) or {}
if model_mode == 'completion': # check model mode
agent_prompt_entity = AgentPromptEntity( model_mode = copy_app_model_config_dict.get('model', {}).get('mode', 'completion')
first_prompt=agent_prompt.get('first_prompt', REACT_PROMPT_TEMPLATES['english']['completion']['prompt']), if model_mode == 'completion':
next_iteration=agent_prompt.get('next_iteration', REACT_PROMPT_TEMPLATES['english']['completion']['agent_scratchpad']), agent_prompt_entity = AgentPromptEntity(
) first_prompt=agent_prompt.get('first_prompt', REACT_PROMPT_TEMPLATES['english']['completion']['prompt']),
else: next_iteration=agent_prompt.get('next_iteration', REACT_PROMPT_TEMPLATES['english']['completion']['agent_scratchpad']),
agent_prompt_entity = AgentPromptEntity( )
first_prompt=agent_prompt.get('first_prompt', REACT_PROMPT_TEMPLATES['english']['chat']['prompt']), else:
next_iteration=agent_prompt.get('next_iteration', REACT_PROMPT_TEMPLATES['english']['chat']['agent_scratchpad']), agent_prompt_entity = AgentPromptEntity(
) first_prompt=agent_prompt.get('first_prompt', REACT_PROMPT_TEMPLATES['english']['chat']['prompt']),
next_iteration=agent_prompt.get('next_iteration', REACT_PROMPT_TEMPLATES['english']['chat']['agent_scratchpad']),
)
properties['agent'] = AgentEntity( properties['agent'] = AgentEntity(
provider=properties['model_config'].provider, provider=properties['model_config'].provider,
model=properties['model_config'].model, model=properties['model_config'].model,
strategy=strategy, strategy=strategy,
prompt=agent_prompt_entity, prompt=agent_prompt_entity,
tools=agent_tools, tools=agent_tools,
max_iteration=agent_dict.get('max_iteration', 5) max_iteration=agent_dict.get('max_iteration', 5)
) )
if len(dataset_ids) > 0: if len(dataset_ids) > 0:
# dataset configs # dataset configs