Completed agent function definition.