Contents

unstructured_text = """The original, historic library building is the Fisher Ames Baker Memorial Library; it opened in 1928 with a collection of 240,000 volumes. The building was designed by Jens Fredrick Larson, modeled after Independence Hall in Philadelphia, and funded by a gift to Dartmouth College by George Fisher Baker in memory of his uncle, Fisher Ames Baker, Dartmouth class of 1859. The facility was expanded in 1941 and 1957–1958 and received its one millionth volume in 1970.

In 1992, John Berry and the Baker family donated US $30 million for the construction of a new facility, the Berry Library designed by architect Robert Venturi, adjoining the Baker Library. The new complex, the Baker-Berry Library, opened in 2000 and was completed in 2002.[6] The Dartmouth College libraries presently hold over 2 million volumes in their collections."""

print(unstructured_text)
The original, historic library building is the Fisher Ames Baker Memorial Library; it opened in 1928 with a collection of 240,000 volumes. The building was designed by Jens Fredrick Larson, modeled after Independence Hall in Philadelphia, and funded by a gift to Dartmouth College by George Fisher Baker in memory of his uncle, Fisher Ames Baker, Dartmouth class of 1859. The facility was expanded in 1941 and 1957–1958 and received its one millionth volume in 1970.

In 1992, John Berry and the Baker family donated US $30 million for the construction of a new facility, the Berry Library designed by architect Robert Venturi, adjoining the Baker Library. The new complex, the Baker-Berry Library, opened in 2000 and was completed in 2002.[6] The Dartmouth College libraries presently hold over 2 million volumes in their collections.
from langchain_dartmouth.llms import ChatDartmouth
from dotenv import find_dotenv, load_dotenv

load_dotenv(find_dotenv())
True
from dataclasses import dataclass


@dataclass
class Event:
    """An event in the timeline"""

    year: int  # The year of the event
    description: str  # The description of the event


@dataclass
class Timeline:
    """A sequence of events"""

    events: list[Event]  # The events of the timeline
from langchain.agents import create_agent

llm = ChatDartmouth(model_name="openai.gpt-oss-120b")

agent = create_agent(model=llm, response_format=Timeline)


prompt = (
    "Extract a succinct timeline of events directly related the Library from the following text: \n\n"
    + unstructured_text
)
/opt/hostedtoolcache/Python/3.11.15/x64/lib/python3.11/site-packages/langgraph/checkpoint/serde/encrypted.py:5: LangChainPendingDeprecationWarning: The default value of `allowed_objects` will change in a future version. Pass an explicit value (e.g., allowed_objects='messages' or allowed_objects='core') to suppress this warning.
  from langgraph.checkpoint.serde.jsonplus import JsonPlusSerializer
response = agent.invoke({"messages": ("human", prompt)})

timeline = response["structured_response"]
for event in timeline.events:
    print(f"{event.year}:\t{event.description}")
1928:	Fisher Ames Baker Memorial Library opens with 240,000 volumes; building designed by Jens Fredrick Larson, modeled after Independence Hall, funded by George Fisher Baker in memory of his uncle.
1941:	First expansion of the historic library building.
1957:	Second phase of expansion (1957‑1958) of the historic library building.
1970:	Library receives its one‑millionth volume.
1992:	John Berry and the Baker family donate US $30 million for a new facility, the Berry Library, designed by architect Robert Venturi.
2000:	Baker‑Berry Library complex (original Baker Library plus new Berry Library) opens to the public.
2002:	Construction of the Baker‑Berry Library complex is fully completed.