1414
1515import deepmerge
1616import openai_client
17+ from assistant_extensions .ai_clients .model import CompletionMessageImageContent
1718from assistant_extensions .attachments import AttachmentsExtension
1819from content_safety .evaluators import CombinedContentSafetyEvaluator
1920from openai .types .chat import ChatCompletionMessageParam
3738from . import legacy
3839from .agents .artifact_agent import Artifact , ArtifactAgent , ArtifactConversationInspectorStateProvider
3940from .agents .document_agent import DocumentAgent
40- from .agents .form_fill_extension import FormFillExtension , LLMConfig
4141from .config import AssistantConfigModel
42+ from .form_fill_extension import FormFillExtension , LLMConfig
4243
4344logger = logging .getLogger (__name__ )
4445
@@ -131,8 +132,8 @@ async def on_chat_message_created(
131132 - @assistant.events.conversation.message.on_created
132133 """
133134
134- # update the participant status to indicate the assistant is thinking
135- async with send_error_message_on_exception (context ), context .set_status ("thinking ..." ):
135+ # update the participant status to indicate the assistant is responding
136+ async with send_error_message_on_exception (context ), context .set_status ("responding ..." ):
136137 #
137138 # NOTE: we're experimenting with agents, if they are enabled, use them to respond to the conversation
138139 #
@@ -183,7 +184,7 @@ async def on_conversation_created(context: ConversationContext) -> None:
183184
184185
185186async def welcome_message_form_fill (context : ConversationContext ) -> None :
186- async with send_error_message_on_exception (context ), context .set_status ("thinking ..." ):
187+ async with send_error_message_on_exception (context ), context .set_status ("responding ..." ):
187188 await form_fill_execute (context , None )
188189
189190
@@ -193,7 +194,7 @@ async def welcome_message_create_document(
193194 message : ConversationMessage | None ,
194195 metadata : dict [str , Any ],
195196) -> None :
196- async with send_error_message_on_exception (context ), context .set_status ("thinking ..." ):
197+ async with send_error_message_on_exception (context ), context .set_status ("responding ..." ):
197198 await create_document_execute (config , context , message , metadata )
198199
199200
@@ -223,6 +224,7 @@ async def form_fill_execute(context: ConversationContext, message: ConversationM
223224 Execute the form fill agent to respond to the conversation message.
224225 """
225226 config = await assistant_config .get (context .assistant )
227+ participants = await context .get_participants (include_inactive = True )
226228 await form_fill_extension .execute (
227229 llm_config = LLMConfig (
228230 openai_client_factory = lambda : openai_client .create_client (config .service_config ),
@@ -231,7 +233,7 @@ async def form_fill_execute(context: ConversationContext, message: ConversationM
231233 ),
232234 config = config .agents_config .form_fill_agent ,
233235 context = context ,
234- latest_user_message = message . content if message else None ,
236+ latest_user_message = _format_message ( message , participants . participants ) if message else None ,
235237 latest_attachment_filenames = message .filenames if message else [],
236238 get_attachment_content = form_fill_extension_get_attachment (context , config ),
237239 )
@@ -251,8 +253,26 @@ async def get(filename: str) -> str:
251253 if not messages :
252254 return ""
253255
254- # filter down to the messages that contain the attachment (ie. don't include the system messages)
255- return "\n \n " .join ((str (message .content ) for message in messages if "<ATTACHMENT>" in str (message .content )))
256+ # filter down to the message with the attachment
257+ user_message = next (
258+ (message for message in messages if "<ATTACHMENT>" in str (message )),
259+ None ,
260+ )
261+ if not user_message :
262+ return ""
263+
264+ content = user_message .content
265+ match content :
266+ case str ():
267+ return content
268+
269+ case list ():
270+ for part in content :
271+ match part :
272+ case CompletionMessageImageContent ():
273+ return part .data
274+
275+ return ""
256276
257277 return get
258278
0 commit comments