Google 의 agent 프레임워크, langfun


Google 에서 Agent 구축을 파이썬 클래스 정의로 진행할 수 있는 있도록 하는 라이브러리를 만들었다. 사용법이 상당히 직관적이다.

We hypothize that LLMs trained on code installed a strong tendency for LLMs to follow schema such as class definitions. Therefore, LLMs could be guided by the fields defined in a structure. The code below illustrates how Chain-of-Thoughts could be implemented:

question = (
    'Janet’s ducks lay 16 eggs per day. She eats three for breakfast every morning and bakes muffins for her friends every day with four. '
    'She sells the remainder at the farmers\' market daily for $2 per fresh duck egg. '
    'How much in dollars does she make every day at the farmers\' market?')

class Step(pg.Object):
  description: str
  step_output: float

class Solution(pg.Object):
  steps: list[Step]
  final_answer: int

r = lf.query(prompt=question, schema=Solution, lm=lf.llms.Gpt4o())
print(r)

Output:

Solution(
  steps = [
    0 : Step(
      description = 'Calculate total eggs laid by ducks per day',
      step_output = 16.0
    ),
    1 : Step(
      description = 'Eggs eaten for breakfast',
      step_output = 3.0
    ),
    2 : Step(
      description = 'Eggs used for baking muffins',
      step_output = 4.0
    ),
    3 : Step(
      description = "Eggs remaining to be sold at the farmers' market",
      step_output = 9.0
    ),
    4 : Step(
      description = 'Calculate the earnings from selling the remaining eggs',
      step_output = 18.0
    )
  ],
  final_answer = 18
)

Reference




    Enjoy Reading This Article?

    Here are some more articles you might like to read next:

  • Deepseek-R1 모델
  • 학습할때 메모리가 터진다고? Cut Your Losses!
  • GRPO 대신 DAPO: RL 최적화로 LLM 추론 능력 끌어올리기
  • DeepSeek-V3 기술 요약
  • python accelerate 라이브러리 함수 조사기