본문으로 건너뛰기

시스템 메시지

시스템 메시지는 에이전트의 전반적인 동작, 어조 또는 역할을 정의합니다. 언어 모델에 "당신은 도움이 되는 어시스턴트입니다" 또는 "JSON 형식으로 간결하게 답변하세요." 와 같은 상위 수준의 지시사항을 제공합니다.

시스템 메시지는 모델이 후속 사용자 입력을 어떻게 해석하고 어떻게 응답해야 하는지를 안내합니다. 일반적으로 사용자나 어시스턴트 메시지보다 앞에, 메시지 배열의 맨 처음에 배치됩니다.

메시지 배열의 첫 번째 요소에 직접 시스템 메시지를 포함하여 기본 시스템 메시지를 재정의할 수 있습니다.

[
{
"role": "system",
"contents": [
{
"type": "text",
"text": "You are an assistant who always speaks like a pirate."
}
]
},
{
"role": "user",
"contents": [
{
"type": "text",
"text": "Explain how memory management works in Rust."
}
]
}
]

이제 모델은 기본 중립적인 어시스턴트 스타일 대신 해적 페르소나에 따라 응답합니다:

{
"role": "assistant",
"contents": [
{
"type": "text",
"text": "Arrr, matey! In Rust, the seas be ruled by ownership and borrowing. Each variable be owning its treasure, and when it sails out of scope, the booty be dropped overboard — no garbage crew needed!"
}
]
}

LM은 내부 기본값 대신 개발자가 정의한 시스템 메시지를 사용하므로, 개발자가 모델의 어조, 페르소나, 작업별 동작을 완전히 커스터마이즈할 수 있습니다.

예제

import asyncio

import ailoy as ai


async def main():
lm = await ai.LangModel.new_local("Qwen/Qwen3-0.6B")
agent = ai.Agent(lm)

messages = [
ai.Message(
role="system",
# `contents`에 텍스트 파트가 하나만 있으면 단일 문자열로 작성할 수 있습니다.
contents="You are an assistant who always speaks like a pirate.",
),
ai.Message(
role="user",
# 일반적으로 `contents`는 `Part`의 리스트로 작성됩니다.
contents=[
ai.Part.Text(text="Explain how memory management works in Rust.")
],
),
]
async for resp in agent.run(messages):
if isinstance(resp.message.contents[0], ai.Part.Text):
print(resp.message.contents[0].text)


if __name__ == "__main__":
asyncio.run(main())
Arrr, matey! In Rust, the seas be ruled by ownership and borrowing. Each variable be owning its treasure, and when it sails out of scope, the booty be dropped overboard — no garbage crew needed!

참고사항

  • 시스템 메시지는 항상 시퀀스의 첫 번째 메시지로 배치하세요. 다른 곳에 배치하면 오류나 정의되지 않은 동작이 발생할 수 있습니다.
  • 시스템 메시지는 동일한 대화 내의 모든 후속 응답에 영향을 미칩니다.
  • 세션 중에 시스템 동작을 초기화하거나 변경하려면 새 대화를 시작하거나 새 메시지 목록의 시작 부분에 새 시스템 메시지를 명시적으로 포함하세요.