Atomic-agent 및 Instructor를 기반으로 하는 간단한 동적 다중 에이전트 프레임워크입니다. 데이터와 스키마 검증 및 직렬화를 위해 Pydantic의 강력한 기능을 사용합니다.
함수 호출 또는 GraphQL 변형 의 공유 언어를 사용하여 시스템 프롬프트로 구성된 에이전트 구성
라우터는 LLM을 사용하여 복잡한 '복합' 사용자 프롬프트를 처리하고 자동으로 에이전트의 최상의 순서로 라우팅합니다.
OpenAI, AWS Bedrock 또는 groq를 통해 생성
참고: !! framework is at an early stage !!
- 주요 변경 사항은 부 버전을 늘려 표시됩니다(주요 버전은 여전히 0임).
공유 언어를 사용하여 에이전트를 조정하기 위해 에이전트 지향 프로그래밍 접근 방식을 사용하는 LLM 기반 에이전트 프레임워크입니다.
에이전트 언어는 함수 호출 기반이거나 GraphQL 기반일 수 있습니다.
프레임워크는 일반적이며 이름, 설명, 허용된 입력 호출 및 허용된 출력 호출 측면에서 에이전트를 정의할 수 있습니다.
에이전트는 칠판을 사용하여 간접적으로 통신합니다. 언어는 (함수 또는 GraphQL 변형) 호출로 구성됩니다. 각 에이전트는 입력으로 이해하는 내용과 생성할 수 있는 호출을 지정합니다. 이런 방식으로 에이전트는 서로의 출력을 이해할 수 있습니다.
라우터는 사용자 프롬프트를 받아 에이전트 실행 계획을 생성합니다.
실행 계획은 가장 적합한 에이전트의 최상의 순서를 사용하여 사용자 프롬프트를 처리합니다.
라우터는 각 에이전트에 맞게 사용자 프롬프트를 다시 작성하므로 품질이 향상되고 원치 않는 출력이 방지됩니다.
참고: 선택적으로 라우터를 별도로 실행하여 라우터가 생성한 실행 계획에 대한 인간 참여형 피드백을 허용할 수 있습니다. 이러한 방식으로 사용자는 생성 에이전트가 실제로 실행되기 전에 라우터와 더 많이 협력할 수 있습니다.
마지막으로 출력은 (함수 또는 GraphQL) 호출의 정렬된 목록 형식으로 반환됩니다.
이 접근 방식에 대해 자세히 알아보려면 이 매체 기사를 참조하세요.
framework is at an early stage
. 평가자는 현재 구현되지 않습니다. 통합 시 사용되는 에이전트 정의의 종류에 따라 클라이언트는 다음을 수행해야 합니다.
이것은 데모 '심 라이프' 월드 빌더입니다. 사용자 프롬프트를 처리하기 위해 3개의 에이전트(Creature Creature, Vegetation Creator, Relationship Creator)를 사용합니다. 에이전트는 기능 측면에서 정의됩니다. 출력은 Sim Life 세계를 구축하기 위해 클라이언트가 구현할 수 있는 일련의 함수 호출입니다.
AddCreature 함수:
function_add_creature = FunctionSpecSchema (
agent_name = creature_agent_name ,
function_name = "AddCreature" ,
description = "Adds a new creature to the world (not vegetation)" ,
parameters = [
ParameterSpec ( name = "creature_name" , type = ParameterType . string ),
ParameterSpec ( name = "allowed_terrain" , type = ParameterType . string , allowed_values = terrain_types ),
ParameterSpec ( name = "age" , type = ParameterType . int ),
ParameterSpec ( name = "icon_name" , type = ParameterType . string , allowed_values = creature_icons ),
]
)
AddCreatureRelationship 함수:
function_add_relationship = FunctionSpecSchema (
agent_name = relationship_agent_name ,
function_name = "AddCreatureRelationship" ,
description = "Adds a new relationship between two creatures" ,
parameters = [
ParameterSpec (
name = "from_name" , type = ParameterType . string
),
ParameterSpec (
name = "to_name" , type = ParameterType . string
),
ParameterSpec (
name = "relationship_name" ,
type = ParameterType . string ,
allowed_values = [ "eats" , "buys" , "feeds" , "sells" ],
),
],
)
Creature Creator 에이전트는 다음과 같이 선언적으로 정의됩니다.
에이전트는 칠판을 통해 동일한 기능 정의를 재사용하여 간접적으로 협업하고 정보를 교환할 수 있습니다.
def build_creature_agent ():
agent_definition = FunctionAgentDefinition (
agent_name = "Creature Creator" ,
description = "Creates new creatures given the user prompt. Ensures that ALL creatures mentioned by the user are created." ,
accepted_functions = [ function_add_creature , function_add_relationship ],
input_schema = FunctionAgentInputSchema ,
initial_input = FunctionAgentInputSchema (
functions_allowed_to_generate = [ function_add_creature ],
previously_generated_functions = []
),
output_schema = FunctionAgentOutputSchema ,
topics = [ "creature" ]
)
return agent_definition
Creature Creator 에이전트에 대한 참고 사항:
function_add_relationship
에 의해 정의된 "AddRelationship" 함수를 이해합니다. 자세한 내용은 예제 소스 코드를 참조하세요. 이것은 데모 '심 라이프' 월드 빌더입니다. 사용자 프롬프트를 처리하기 위해 3개의 에이전트(Creature Creature, Vegetation Creator, Relationship Creator)를 사용합니다. 에이전트는 GraphQL 입력 스키마 측면에서 선언적으로 정의되며 생성된 변형이 허용됩니다. 출력은 클라이언트가 Sim Life 세계를 구축하기 위해 실행할 수 있는 일련의 GraphQL 돌연변이입니다.
GraphQL 스키마:
type Creature {
id : ID !
creature_name : String !
allowed_terrain : TerrainType !
age : Int !
icon_name : IconType !
}
type Vegetation {
id : ID !
vegetation_name : String !
icon_name : IconType !
allowed_terrain : TerrainType !
}
type Relationship {
id : ID !
from_name : String !
to_name : String !
relationship_kind : RelationshipType !
}
...
에이전트가 생성하기를 원하는 GraphQL 돌연변이는 각 에이전트마다 다릅니다.
생물 창조자 에이전트:
type Mutation {
addCreature ( input : CreatureInput ! ): Creature !
}
input CreatureInput {
creature_name : String !
allowed_terrain : TerrainType !
age : Int !
icon_name : IconType !
}
식물 생성자 에이전트:
type Mutation {
addVegetation ( input : VegetationInput ! ): Vegetation !
}
input VegetationInput {
vegetation_name : String !
icon_name : IconType !
allowed_terrain : TerrainType !
}
Creature Creator 에이전트는 다음과 같이 선언적으로 정의됩니다.
에이전트는 기본적으로 프롬프트와 함께 입력 및 출력 스키마의 구성입니다.
에이전트는 동일한 GraphQL 스키마 및 돌연변이 호출을 재사용하여 칠판을 통해 간접적으로 협업하고 정보를 교환합니다.
creatures_graphql = _read_schema ( "creature.graphql" )
creature_mutations_graphql = _read_schema ( "creature.mutations.graphql" )
def build_creature_agent ():
agent_definition = GraphQLAgentDefinition (
agent_name = "Creature Creator" ,
description = "Creates new creatures given the user prompt. Ensures that ALL creatures mentioned by the user are created." ,
accepted_graphql_schemas = [ creatures_graphql , creature_mutations_graphql ],
input_schema = GraphQLAgentInputSchema ,
initial_input = GraphQLAgentInputSchema (
mutations_allowed_to_generate = [ creature_mutations_graphql ],
previously_generated_mutations = []
),
output_schema = GraphQLAgentOutputSchema ,
topics = [ "creature" ]
)
return agent_definition
이 에이전트에 대한 참고 사항:
creature_mutations_graphql
에 의해 정의된 돌연변이만 생성할 수 있습니다.creature_mutations_graphql
)을 알 수 있습니다.creatures_graphql
에 의해 정의된 공유 GraphQL 스키마를 이해합니다.에이전트를 함께 사용하여 채팅 봇을 구성할 수 있습니다.
from gpt_multi_atomic_agents import functions_expert_service , config
from . import agents
def run_chat_loop ( given_user_prompt : str | None = None ) -> list :
CHAT_AGENT_DESCRIPTION = "Handles users questions about an ecosystem game like Sim Life"
agent_definitions = [
build_creature_agent (), build_relationship_agent (), build_vegatation_agent () # for more capabilities, add more agents here
]
_config = config . Config (
ai_platform = config . AI_PLATFORM_Enum . bedrock_anthropic ,
model = config . ANTHROPIC_MODEL ,
max_tokens = config . ANTHROPIC_MAX_TOKENS ,
is_debug = False
)
return functions_expert_service . run_chat_loop ( agent_definitions = agent_definitions , chat_agent_description = CHAT_AGENT_DESCRIPTION , _config = _config , given_user_prompt = given_user_prompt )
참고:
given_user_prompt
설정되지 않은 경우run_chat_loop()
키보드에서 사용자 입력을 기다립니다.
자세한 내용은 예제 소스 코드를 참조하세요.
사용자 입력:
Add a sheep that eats grass
산출:
Generated 3 function calls
[Agent: Creature Creator] AddCreature( creature_name=sheep, icon_name=sheep-icon, land_type=prairie, age=1 )
[Agent: Plant Creator] AddPlant( plant_name=grass, icon_name=grass-icon, land_type=prairie )
[Agent: Relationship Creator] AddCreatureRelationship( from_name=sheep, to_name=grass, relationship_name=eats )
프레임워크에는 동적 라우터가 있으므로 다음과 같이 더 복잡한 '복합' 프롬프트를 처리할 수 있습니다.
풀을 먹는 소를 추가해 보세요. 인간을 추가하세요 - 소가 인간에게 먹이를 줍니다. 인간을 잡아먹는 외계인도 추가하세요. 인간도 소를 먹는다.
라우터는 사용할 에이전트, 실행 순서, 각 에이전트에 보낼 프롬프트를 파악합니다.
선택적으로 에이전트를 실제로 실행하기 전에 생성된 계획에 대한 사용자 피드백을 사용하여 라우터를 다시 실행할 수 있습니다.
그러면 추천 에이전트가 순서대로 실행되어 공유 블랙보드에 결과가 쌓이게 됩니다.
마지막으로 프레임워크는 결과 호출을 결합하여 클라이언트에 반환합니다.
사용자 입력:
Add a sheep that eats grass
산출:
['mutation {n addCreature(input: {n creature_name: "sheep",n allowed_terrain: GRASSLAND,n age: 2,n icon_name: SHEEPn }) {n creature_namen allowed_terrainn agen icon_namen }n }']
['mutation {', ' addVegetation(input: {', ' vegetation_name: "Grass",', ' icon_name: GRASS,', ' allowed_terrain: LAND', ' }) {', ' vegetation_name', ' icon_name', ' allowed_terrain', ' }', '}']
['mutation {', ' addCreatureRelationship(input: {', ' from_name: "Sheep",', ' to_name: "Grass",', ' relationship_kind: EATS', ' }) {', ' id', ' }', '}']
Python 3.11 및 시 설치
종속성을 설치합니다.
poetry install
OpenAI의 경우:
export OPENAI_API_KEY="xxx"
이를 쉘 초기화 스크립트( ~/.zprofile
또는 유사)에 추가하십시오.
현재 터미널에 로드:
source ~/.zprofile
테스트 스크립트:
./test.sh
자세한 내용은 예제 소스 코드를 참조하세요.