Lesson_6_student - Essay writer graph.stream errors out with gemini-pro in colab

I am trying Essay Writer Lesson_6_student in Colab using Gemini AI. I am getting

AttributeError: 'str' object has no attribute 'content'

When I execute step.

thread = {"configurable": {"thread_id": "1"}}
for s in graph.stream({
    'task': "what is the difference between langchain and langsmith",
    "max_revisions": 2,
    "revision_number": 1,
}, thread):
    print(s)

I understand the issue is related to JSON output from gemini-pro model and not sure how to make it work. I am using langchain_google_genai library. Here is the reference I used to get JSON output. Generate JSON output with the Gemini API  |  Google for Developers.

Here are the code snippet of changes I made for Gemini:

import typing_extensions as typing
class JsonContent(typing.TypedDict):
  content: str

from langchain_google_genai import GoogleGenerativeAI
model = GoogleGenerativeAI(model="gemini-1.5-pro",generation_config={"response_mime_type": "application/json","response_schema": list[JsonContent]})


All the steps after that went through fine and able to compile the graph.

But when I execute below step, it is throwing error.

thread = {"configurable": {"thread_id": "1"}}
for s in graph.stream({
    'task': "what is the difference between langchain and langsmith",
    "max_revisions": 2,
    "revision_number": 1,
}, thread):
    print(s)

Here is the error:

Hi learner4,

This seems to be an issue with the langgraph library itself maybe? I suggest that you post the issue at the official GitHub repository of langgraph, like this one:

Good luck.
Best,

Rosa

Thanks for pointing me to the GitHub issue. In that someone asked OP to try using chat model. I updated model to ChatGoogleGenerativeAI & got partial success.

from langchain_google_genai import ChatGoogleGenerativeAI

model = ChatGoogleGenerativeAI(model="gemini-1.5-pro",generation_config={"response_mime_type": "application/json",
                                                 "response_schema": list[JsonContent]})

When I executed following, I got the plan_node() execution but it is now failing in research_plan_node with following error:

ChatGoogleGenerativeAIError: Invalid argument provided to Gemini: 400 * GenerateContentRequest.tools[0].function_declarations[0].parameters.properties[queries].items: missing field.

thread = {"configurable": {"thread_id": "1"}}
for s in graph.stream({
    'task': "what is the difference between langchain and langsmith",
    "max_revisions": 2,
    "revision_number": 1,
}, thread):
    print(s)